NAME List.Prioritized - List which sorts elements by prirority SYNOPSIS // Import List.Prioritized module. JSAN.use('List.Prioritized'); var list = new List.Prioritized(); list.insert("B", 2); list.insert("A", 1); list.insert("C", 3); for (var i = 0; i < list.length; i++) alerty(list[i]) // gives A, B and C list.remove("A"); list.removeAt(1); alert(list[0]+", "+list.length); // gives "B, 1" var list2 = new List.Prioritized(); list.insert("A", 1); list.insert("D", 4); list2.insert("C", 3); list2.insert("0", 0); var i = new List.Prioritized.Iterator(list, list2); while (i.hasNext()) alert(i.getNext()) // gives 0, A, B, C, D i.reset(); alert(i.getNext()) // gives 0 DESCRIPTION This module defines class which adds list with elements sorted by priority. CLASSES List.Prioritized class This class implements list which keeps its elements sorted by priority value. It has interface simmilar to standard Array, but it only allows to add elements by insert() method (standard Array methods which can be used for this purpose like push() or unshift() throws exceptions in this class). new List.Prioritized() Create new object. It takes no arguments. list.insert(ITEM, PRIORITY) Add new element ITEM with priority PRIORITY to this list. Returns ITEM list.remove(ITEM) Remove ITEM from list. Returns index of removed element or null when none elements was removed. list.push() This operation cannot be used in this class, it throws exception. list.unshift() This operation cannot be used in this class, it throws exception. list.pop() It works like Array.pop() but also change internal structure. list.shift() It works like Array.pop() but also change internal structure. list.splice() Works simmilar to Array.splice() but only two argument version is supported. When called with > 2 arguments this method throws exception. List.Prioritized.Iterator class Define List.Prioritized iteratior class. It can be used to iterate List.Iterator lists in priority order. It can iterate one or more list simultaneously. new List.Prioritized.Iterator([LIST1, [LIST2, ...]]) Create new iterator which will process all elements of LIST1, LIST2... in priority order. iterator.hasNext() Checks that next element is avaialble. Returns false when all elements was already processed, true otherwise. iterator.getNext() Return next element and increment internal index counter. When all elements was already processed returns undefined. iterator.reset() Reset internal index counter to initial value. All further getNext() operations will be processed from start of the list. CAVEATS and NOTES * Only iterators for 1, 2 or 3 lists are implemented AUTHOR Pawel Chmielowski COPYRIGHT Copyright (c) 2005 Pawel Chmielowski. All rights reserved. This module is free software; you can redistribute it and/or modify it under the terms of the LGPL license.