typescript-collections

  • Version 1.3.3
  • Published
  • 575 kB
  • No dependencies
  • MIT license

Install

npm i typescript-collections
yarn add typescript-collections
pnpm add typescript-collections

Overview

A complete, fully tested data structure library written in TypeScript.

Index

Variables

Classes

Variables

variable arrays

var arrays: typeof _arrays;

    variable util

    var util: typeof _util;

      Classes

      class Bag

      class Bag<T> {}

        constructor

        constructor(toStrFunction?: (item: T) => string);
        • Creates an empty bag. A bag is a special kind of set in which members are allowed to appear more than once. If the inserted elements are custom objects a function which converts elements to unique strings must be provided. Example:

          function petToString(pet) { return pet.name; }

          Parameter toStrFunction

          optional function used to convert elements to strings. If the elements aren't strings or if toString() is not appropriate, a custom function which receives an object and returns a unique string must be provided.

        method add

        add: (element: T, nCopies?: number) => boolean;
        • Adds nCopies of the specified object to this bag.

          Parameter element

          element to add.

          Parameter nCopies

          the number of copies to add, if this argument is undefined 1 copy is added. {boolean} true unless element is undefined.

        method clear

        clear: () => void;
        • Removes all of the elements from this bag.

        method contains

        contains: (element: T) => boolean;
        • Returns true if this bag contains the specified element.

          Parameter element

          element to search for. {boolean} true if this bag contains the specified element, false otherwise.

        method count

        count: (element: T) => number;
        • Counts the number of copies of the specified object in this bag.

          Parameter element

          the object to search for.. {number} the number of copies of the object, 0 if not found

        method forEach

        forEach: (callback: util.ILoopFunction<T>) => void;
        • Executes the provided function once for each element present in this bag, including multiple copies.

          Parameter callback

          function to execute, it is invoked with one argument: the element. To break the iteration you can optionally return false.

        method isEmpty

        isEmpty: () => boolean;
        • Returns true if this bag contains no elements. {boolean} true if this bag contains no elements.

        method remove

        remove: (element: T, nCopies?: number) => boolean;
        • Removes nCopies of the specified object to this bag. If the number of copies to remove is greater than the actual number of copies in the Bag, all copies are removed.

          Parameter element

          element to remove.

          Parameter nCopies

          the number of copies to remove, if this argument is undefined 1 copy is removed. {boolean} true if at least 1 element was removed.

        method size

        size: () => number;
        • Returns the number of elements in this bag. {number} the number of elements in this bag.

        method toArray

        toArray: () => T[];
        • Returns an array containing all of the elements in this big in arbitrary order, including multiple copies. {Array} an array containing all of the elements in this bag.

        method toSet

        toSet: () => Set<T>;
        • Returns a set of unique elements in this bag. {collections.Set} a set of unique elements in this bag.

        class BSTree

        class BSTree<T> extends BSTreeKV<T, T> {}
        • Special-case of the binary search tree in which the search key is equal to the element type. This definition is suitable when the element type can not be split between what defines its order and what does not (eg. primitive types as opposed to indexed records).

          The table below shows some use-case examples for both interfaces:

          element type | most suitable interface ------------------------------------|---------------------------- number | BSTree string | BSTree { order: number, data: string } | BSTreeKV<{order: number}, {order: number, data: string}>

          See Also

          • BSTreeKV

        class BSTreeKV

        class BSTreeKV<K, V extends K> {}
        • General binary search tree implementation.

          This interface allows one to search elements using a subset of their attributes (thus the tree can be used as an index for complex objects). The attributes required to define an ordering in the tree must be defined in the type K. Any additional attribute must be defined in the type V.

          See Also

          • BSTree

        constructor

        constructor(compareFunction?: util.ICompareFunction<K>);
        • Creates an empty binary search tree. A binary search tree is a binary tree in which each internal node stores an element such that the elements stored in the left subtree are less than it and the elements stored in the right subtree are greater. Formally, a binary search tree is a node-based binary tree data structure which has the following properties: The left subtree of a node contains only nodes with elements less than the node's element The right subtree of a node contains only nodes with elements greater than the node's element Both the left and right subtrees must also be binary search trees. If the inserted elements are custom objects a compare function must be provided at construction time, otherwise the <=, === and >= operators are used to compare elements. Example: function compare(a, b) { if (a is less than b by some ordering criterion) { return -1; } if (a is greater than b by the ordering criterion) { return 1; } // a must be equal to b return 0; }

          Parameter compareFunction

          optional function used to compare two elements. Must return a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

        method add

        add: (element: V) => boolean;
        • Adds the specified element to this tree if it is not already present.

          Parameter element

          the element to insert. {boolean} true if this tree did not already contain the specified element.

        method clear

        clear: () => void;
        • Removes all of the elements from this tree.

        method contains

        contains: (element: K) => boolean;
        • Returns true if this tree contains the specified element.

          Parameter element

          element to search for. {boolean} true if this tree contains the specified element, false otherwise.

        method forEach

        forEach: (callback: util.ILoopFunction<V>) => void;
        • Executes the provided function once for each element present in this tree in inorder. Equivalent to inorderTraversal.

          Parameter callback

          function to execute, it is invoked with one argument: the element value, to break the iteration you can optionally return false.

        method height

        height: () => number;
        • Returns the height of this tree. {number} the height of this tree or -1 if is empty.

        method inorderTraversal

        inorderTraversal: (callback: util.ILoopFunction<V>) => void;
        • Executes the provided function once for each element present in this tree in in-order.

          Parameter callback

          function to execute, it is invoked with one argument: the element value, to break the iteration you can optionally return false.

        method isEmpty

        isEmpty: () => boolean;
        • Returns true if this tree contains no elements. {boolean} true if this tree contains no elements.

        method levelTraversal

        levelTraversal: (callback: util.ILoopFunction<V>) => void;
        • Executes the provided function once for each element present in this tree in level-order.

          Parameter callback

          function to execute, it is invoked with one argument: the element value, to break the iteration you can optionally return false.

        method maximum

        maximum: () => V | undefined;
        • Returns the maximum element of this tree. {*} the maximum element of this tree or undefined if this tree is is empty.

        method minimum

        minimum: () => V | undefined;
        • Returns the minimum element of this tree. {*} the minimum element of this tree or undefined if this tree is is empty.

        method postorderTraversal

        postorderTraversal: (callback: util.ILoopFunction<V>) => void;
        • Executes the provided function once for each element present in this tree in post-order.

          Parameter callback

          function to execute, it is invoked with one argument: the element value, to break the iteration you can optionally return false.

        method preorderTraversal

        preorderTraversal: (callback: util.ILoopFunction<V>) => void;
        • Executes the provided function once for each element present in this tree in pre-order.

          Parameter callback

          function to execute, it is invoked with one argument: the element value, to break the iteration you can optionally return false.

        method remove

        remove: (element: K) => boolean;
        • Removes the specified element from this tree if it is present. {boolean} true if this tree contained the specified element.

        method search

        search: (element: K) => V | undefined;
        • Looks for the value with the provided search key.

          Parameter element

          The key to look for {Object} The value found or undefined if it was not found.

        method size

        size: () => number;
        • Returns the number of elements in this tree. {number} the number of elements in this tree.

        method toArray

        toArray: () => V[];
        • Returns an array containing all of the elements in this tree in in-order. {Array} an array containing all of the elements in this tree in in-order.

        class DefaultDictionary

        class FactoryDictionary<K, V> extends Dictionary<K, V> {}

          constructor

          constructor(defaultFactoryFunction: () => V, toStrFunction?: (key: K) => string);
          • Creates an empty dictionary. Dictionaries map keys to values; each key can map to at most one value. This implementation accepts any kind of objects as keys.

            The default factory function should return a new object of the provided type. Example: function petFactory() { return new Pet(); }

            If the keys are custom objects a function which converts keys to unique strings must be provided. Example: function petToString(pet) { return pet.name; }

            Parameter defaultFactoryFunction

            function used to create a default object.

            Parameter toStrFunction

            optional function used to convert keys to strings. If the keys aren't strings or if toString() is not appropriate, a custom function which receives a key and returns a unique string must be provided.

          property defaultFactoryFunction

          protected defaultFactoryFunction: () => V;
          • Factory to create default values. {function(Object):string}

          method getValue

          getValue: (key: K) => V;
          • Returns the value to which this dictionary maps the specified key. Returns a default value created by the factory passed in the constructor, if this dictionary contains no mapping for this key. The missing key will automatically be added to the dictionary.

            Parameter key

            key whose associated value is to be returned. {*} the value to which this dictionary maps the specified key or a default value if the map contains no mapping for this key.

          method setDefault

          setDefault: (key: K, defaultValue: V) => V;
          • Associates the specified default value with the specified key in this dictionary, if it didn't contain the key yet. If the key existed, the existing value will be used.

            Parameter key

            key with which the specified value is to be associated.

            Parameter defaultValue

            default value to be associated with the specified key. {*} previous value associated with the specified key, or the default value, if the key didn't exist yet.

          class Dictionary

          class Dictionary<K, V> {}

            constructor

            constructor(toStrFunction?: (key: K) => string);
            • Creates an empty dictionary. Dictionaries map keys to values; each key can map to at most one value. This implementation accepts any kind of objects as keys.

              If the keys are custom objects a function which converts keys to unique strings must be provided. Example: function petToString(pet) { return pet.name; }

              Parameter toStrFunction

              optional function used to convert keys to strings. If the keys aren't strings or if toString() is not appropriate, a custom function which receives a key and returns a unique string must be provided.

            property nElements

            protected nElements: number;
            • Number of elements in the list. {number}

            property table

            protected table: { [key: string]: IDictionaryPair<K, V> };
            • Object holding the key-value pairs. {Object}

            property toStr

            protected toStr: (key: K) => string;
            • Function used to convert keys to strings. {function(Object):string}

            method clear

            clear: (this: collections.Dictionary) => void;
            • Removes all mappings from this dictionary. {collections.Dictionary}

            method containsKey

            containsKey: (key: K) => boolean;
            • Returns true if this dictionary contains a mapping for the specified key.

              Parameter key

              key whose presence in this dictionary is to be tested. {boolean} true if this dictionary contains a mapping for the specified key.

            method forEach

            forEach: (callback: (key: K, value: V) => any) => void;
            • Executes the provided function once for each key-value pair present in this dictionary.

              Parameter callback

              function to execute, it is invoked with two arguments: key and value. To break the iteration you can optionally return false.

            method getValue

            getValue: (key: K) => V | undefined;
            • Returns the value to which this dictionary maps the specified key. Returns undefined if this dictionary contains no mapping for this key.

              Parameter key

              key whose associated value is to be returned. {*} the value to which this dictionary maps the specified key or undefined if the map contains no mapping for this key.

            method isEmpty

            isEmpty: () => boolean;
            • Returns true if this dictionary contains no mappings. {boolean} true if this dictionary contains no mappings.

            method keys

            keys: () => K[];
            • Returns an array containing all of the keys in this dictionary. {Array} an array containing all of the keys in this dictionary.

            method remove

            remove: (key: K) => V | undefined;
            • Removes the mapping for this key from this dictionary if it is present.

              Parameter key

              key whose mapping is to be removed from the dictionary. {*} previous value associated with specified key, or undefined if there was no mapping for key.

            method setValue

            setValue: (key: K, value: V) => V | undefined;
            • Associates the specified value with the specified key in this dictionary. If the dictionary previously contained a mapping for this key, the old value is replaced by the specified value.

              Parameter key

              key with which the specified value is to be associated.

              Parameter value

              value to be associated with the specified key. {*} previous value associated with the specified key, or undefined if there was no mapping for the key or if the key/value are undefined.

            method size

            size: () => number;
            • Returns the number of keys in this dictionary. {number} the number of key-value mappings in this dictionary.

            method toString

            toString: () => string;

              method values

              values: () => V[];
              • Returns an array containing all of the values in this dictionary. {Array} an array containing all of the values in this dictionary.

              class FactoryDictionary

              class FactoryDictionary<K, V> extends Dictionary<K, V> {}

                constructor

                constructor(defaultFactoryFunction: () => V, toStrFunction?: (key: K) => string);
                • Creates an empty dictionary. Dictionaries map keys to values; each key can map to at most one value. This implementation accepts any kind of objects as keys.

                  The default factory function should return a new object of the provided type. Example: function petFactory() { return new Pet(); }

                  If the keys are custom objects a function which converts keys to unique strings must be provided. Example: function petToString(pet) { return pet.name; }

                  Parameter defaultFactoryFunction

                  function used to create a default object.

                  Parameter toStrFunction

                  optional function used to convert keys to strings. If the keys aren't strings or if toString() is not appropriate, a custom function which receives a key and returns a unique string must be provided.

                property defaultFactoryFunction

                protected defaultFactoryFunction: () => V;
                • Factory to create default values. {function(Object):string}

                method getValue

                getValue: (key: K) => V;
                • Returns the value to which this dictionary maps the specified key. Returns a default value created by the factory passed in the constructor, if this dictionary contains no mapping for this key. The missing key will automatically be added to the dictionary.

                  Parameter key

                  key whose associated value is to be returned. {*} the value to which this dictionary maps the specified key or a default value if the map contains no mapping for this key.

                method setDefault

                setDefault: (key: K, defaultValue: V) => V;
                • Associates the specified default value with the specified key in this dictionary, if it didn't contain the key yet. If the key existed, the existing value will be used.

                  Parameter key

                  key with which the specified value is to be associated.

                  Parameter defaultValue

                  default value to be associated with the specified key. {*} previous value associated with the specified key, or the default value, if the key didn't exist yet.

                class Heap

                class Heap<T> {}

                  constructor

                  constructor(compareFunction?: collections.ICompareFunction<T>);
                  • Creates an empty Heap. A heap is a binary tree, where the nodes maintain the heap property: each node is smaller than each of its children and therefore a MinHeap This implementation uses an array to store elements. If the inserted elements are custom objects a compare function must be provided, at construction time, otherwise the <=, === and >= operators are used to compare elements. Example:

                    function compare(a, b) { if (a is less than b by some ordering criterion) { return -1; } if (a is greater than b by the ordering criterion) { return 1; } // a must be equal to b return 0; }

                    If a Max-Heap is wanted (greater elements on top) you can a provide a reverse compare function to accomplish that behavior. Example:

                    function reverseCompare(a, b) { if (a is less than b by some ordering criterion) { return 1; } if (a is greater than b by the ordering criterion) { return -1; } // a must be equal to b return 0; }

                    Parameter compareFunction

                    optional function used to compare two elements. Must return a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

                  method add

                  add: (element: T) => boolean;
                  • Adds the given element into the heap.

                    Parameter element

                    the element. true if the element was added or fals if it is undefined.

                  method clear

                  clear: () => void;
                  • Removes all of the elements from this heap.

                  method contains

                  contains: (element: T) => boolean;
                  • Returns true if this heap contains the specified element.

                    Parameter element

                    element to search for. {boolean} true if this Heap contains the specified element, false otherwise.

                  method forEach

                  forEach: (callback: collections.ILoopFunction<T>) => void;
                  • Executes the provided function once for each element present in this heap in no particular order.

                    Parameter callback

                    function to execute, it is invoked with one argument: the element value, to break the iteration you can optionally return false.

                  method isEmpty

                  isEmpty: () => boolean;
                  • Checks if this heap is empty. {boolean} true if and only if this heap contains no items; false otherwise.

                  method peek

                  peek: () => T | undefined;
                  • Retrieves but does not remove the root element of this heap. {*} The value at the root of the heap. Returns undefined if the heap is empty.

                  method removeRoot

                  removeRoot: () => T | undefined;
                  • Retrieves and removes the root element of this heap. {*} The value removed from the root of the heap. Returns undefined if the heap is empty.

                  method size

                  size: () => number;
                  • Returns the number of elements in this heap. {number} the number of elements in this heap.

                  class LinkedDictionary

                  class LinkedDictionary<K, V> extends Dictionary<K, V> {}

                    constructor

                    constructor(toStrFunction?: (key: K) => string);

                      method clear

                      clear: (this: collections.LinkedDictionary) => void;
                      • Removes all mappings from this LinkedDictionary. {collections.LinkedDictionary}

                      method forEach

                      forEach: (callback: (key: K, value: V) => any) => void;
                      • Executes the provided function once for each key-value pair present in this LinkedDictionary. It is done in the order of insertion into the LinkedDictionary

                        Parameter callback

                        function to execute, it is invoked with two arguments: key and value. To break the iteration you can optionally return false.

                      method getValue

                      getValue: (key: K) => V | undefined;
                      • Returns the value to which this dictionary maps the specified key. Returns undefined if this dictionary contains no mapping for this key.

                        Parameter key

                        key whose associated value is to be returned. {*} the value to which this dictionary maps the specified key or undefined if the map contains no mapping for this key.

                      method keys

                      keys: () => K[];
                      • Returns an array containing all of the keys in this LinkedDictionary, ordered by insertion order. {Array} an array containing all of the keys in this LinkedDictionary, ordered by insertion order.

                      method remove

                      remove: (key: K) => V | undefined;
                      • Removes the mapping for this key from this dictionary if it is present. Also, if a value is present for this key, the entry is removed from the insertion ordering.

                        Parameter key

                        key whose mapping is to be removed from the dictionary. {*} previous value associated with specified key, or undefined if there was no mapping for key.

                      method setValue

                      setValue: (key: K, value: V) => V | undefined;
                      • Associates the specified value with the specified key in this dictionary. If the dictionary previously contained a mapping for this key, the old value is replaced by the specified value. Updating of a key that already exists maintains its place in the insertion order into the map.

                        Parameter key

                        key with which the specified value is to be associated.

                        Parameter value

                        value to be associated with the specified key. {*} previous value associated with the specified key, or undefined if there was no mapping for the key or if the key/value are undefined.

                      method values

                      values: () => V[];
                      • Returns an array containing all of the values in this LinkedDictionary, ordered by insertion order. {Array} an array containing all of the values in this LinkedDictionary, ordered by insertion order.

                      class LinkedList

                      class LinkedList<T> {}

                        constructor

                        constructor();
                        • Creates an empty Linked List. A linked list is a data structure consisting of a group of nodes which together represent a sequence.

                        property firstNode

                        firstNode: ILinkedListNode<T>;
                        • First node in the list {Object}

                        method add

                        add: (item: T, index?: number) => boolean;
                        • Adds an element to this list.

                          Parameter item

                          element to be added.

                          Parameter index

                          optional index to add the element. If no index is specified the element is added to the end of this list. {boolean} true if the element was added or false if the index is invalid or if the element is undefined.

                        method clear

                        clear: () => void;
                        • Removes all of the elements from this list.

                        method contains

                        contains: (item: T, equalsFunction?: util.IEqualsFunction<T>) => boolean;
                        • Returns true if this list contains the specified element. If the elements inside the list are not comparable with the === operator a custom equals function should be provided to perform searches, the function must receive two arguments and return true if they are equal, false otherwise. Example:

                          const petsAreEqualByName = function(pet1, pet2) { return pet1.name === pet2.name; }

                          Parameter item

                          element to search for.

                          Parameter equalsFunction

                          Optional function used to check if two elements are equal. {boolean} true if this list contains the specified element, false otherwise.

                        method elementAtIndex

                        elementAtIndex: (index: number) => T | undefined;
                        • Returns the element at the specified position in this list.

                          Parameter index

                          desired index. {*} the element at the given index or undefined if the index is out of bounds.

                        method equals

                        equals: (other: any, equalsFunction?: util.IEqualsFunction<T>) => boolean;
                        • Returns true if this list is equal to the given list. Two lists are equal if they have the same elements in the same order.

                          Parameter other

                          the other list.

                          Parameter equalsFunction

                          optional function used to check if two elements are equal. If the elements in the lists are custom objects you should provide a function, otherwise the === operator is used to check equality between elements. {boolean} true if this list is equal to the given list.

                        method first

                        first: () => T | undefined;
                        • Returns the first element in this list. {*} the first element of the list or undefined if the list is empty.

                        method forEach

                        forEach: (callback: util.ILoopFunction<T>) => void;
                        • Executes the provided function once for each element present in this list in order.

                          Parameter callback

                          function to execute, it is invoked with one argument: the element value, to break the iteration you can optionally return false.

                        method indexOf

                        indexOf: (item: T, equalsFunction?: util.IEqualsFunction<T>) => number;
                        • Returns the index in this list of the first occurrence of the specified element, or -1 if the List does not contain this element. If the elements inside this list are not comparable with the === operator a custom equals function should be provided to perform searches, the function must receive two arguments and return true if they are equal, false otherwise. Example:

                          const petsAreEqualByName = function(pet1, pet2) { return pet1.name === pet2.name; }

                          Parameter item

                          element to search for.

                          Parameter equalsFunction

                          Optional function used to check if two elements are equal. {number} the index in this list of the first occurrence of the specified element, or -1 if this list does not contain the element.

                        method isEmpty

                        isEmpty: () => boolean;
                        • Returns true if this list contains no elements. {boolean} true if this list contains no elements.

                        method last

                        last: () => T | undefined;
                        • Returns the last element in this list. {*} the last element in the list or undefined if the list is empty.

                        method remove

                        remove: (item: T, equalsFunction?: util.IEqualsFunction<T>) => boolean;
                        • Removes the first occurrence of the specified element in this list. If the elements inside the list are not comparable with the === operator a custom equals function should be provided to perform searches, the function must receive two arguments and return true if they are equal, false otherwise. Example:

                          const petsAreEqualByName = function(pet1, pet2) { return pet1.name === pet2.name; }

                          Parameter item

                          element to be removed from this list, if present. {boolean} true if the list contained the specified element.

                        method removeElementAtIndex

                        removeElementAtIndex: (index: number) => T | undefined;
                        • Removes the element at the specified position in this list.

                          Parameter index

                          given index. {*} removed element or undefined if the index is out of bounds.

                        method reverse

                        reverse: () => void;
                        • Reverses the order of the elements in this linked list (makes the last element first, and the first element last).

                        method size

                        size: () => number;
                        • Returns the number of elements in this list. {number} the number of elements in this list.

                        method toArray

                        toArray: () => T[];
                        • Returns an array containing all of the elements in this list in proper sequence. {Array.<*>} an array containing all of the elements in this list, in proper sequence.

                        method toString

                        toString: () => string;

                          class MultiDictionary

                          class MultiDictionary<K, V> {}

                            constructor

                            constructor(
                            toStrFunction?: (key: K) => string,
                            valuesEqualsFunction?: util.IEqualsFunction<V>,
                            allowDuplicateValues?: boolean
                            );
                            • Creates an empty multi dictionary. A multi dictionary is a special kind of dictionary that holds multiple values against each key. Setting a value into the dictionary will add the value to an array at that key. Getting a key will return an array, holding all the values set to that key. You can configure to allow duplicates in the values. This implementation accepts any kind of objects as keys.

                              If the keys are custom objects a function which converts keys to strings must be provided. Example:

                              function petToString(pet) { return pet.name; } If the values are custom objects a function to check equality between values must be provided. Example:

                              function petsAreEqualByAge(pet1,pet2) { return pet1.age === pet2.age; }

                              Parameter toStrFunction

                              optional function to convert keys to strings. If the keys aren't strings or if toString() is not appropriate, a custom function which receives a key and returns a unique string must be provided.

                              Parameter valuesEqualsFunction

                              optional function to check if two values are equal.

                              Parameter allowDuplicateValues

                            method clear

                            clear: () => void;
                            • Removes all mappings from this dictionary.

                            method containsKey

                            containsKey: (key: K) => boolean;
                            • Returns true if this dictionary at least one value associatted the specified key.

                              Parameter key

                              key whose presence in this dictionary is to be tested. {boolean} true if this dictionary at least one value associatted the specified key.

                            method getValue

                            getValue: (key: K) => V[];
                            • Returns an array holding the values to which this dictionary maps the specified key. Returns an empty array if this dictionary contains no mappings for this key.

                              Parameter key

                              key whose associated values are to be returned. {Array} an array holding the values to which this dictionary maps the specified key.

                            method isEmpty

                            isEmpty: () => boolean;
                            • Returns true if this dictionary contains no mappings. {boolean} true if this dictionary contains no mappings.

                            method keys

                            keys: () => K[];
                            • Returns an array containing all of the keys in this dictionary. {Array} an array containing all of the keys in this dictionary.

                            method remove

                            remove: (key: K, value?: V) => boolean;
                            • Removes the specified values from the array of values associated with the specified key. If a value isn't given, all values associated with the specified key are removed.

                              Parameter key

                              key whose mapping is to be removed from the dictionary.

                              Parameter value

                              optional argument to specify the value to remove from the array associated with the specified key. {*} true if the dictionary changed, false if the key doesn't exist or if the specified value isn't associated with the specified key.

                            method setValue

                            setValue: (key: K, value: V) => boolean;
                            • Adds the value to the array associated with the specified key, if it is not already present.

                              Parameter key

                              key with which the specified value is to be associated.

                              Parameter value

                              the value to add to the array at the key {boolean} true if the value was not already associated with that key.

                            method size

                            size: () => number;
                            • Returns the number of keys in this dictionary. {number} the number of key-value mappings in this dictionary.

                            method values

                            values: () => V[];
                            • Returns an array containing all of the values in this dictionary. {Array} an array containing all of the values in this dictionary.

                            class MultiRootTree

                            class MultiRootTree {}

                              constructor

                              constructor(rootIds?: string[], nodes?: { [id: string]: string[] });

                                property nodes

                                nodes: { [id: string]: string[] };

                                  property rootIds

                                  rootIds: string[];

                                    method createEmptyNodeIfNotExist

                                    createEmptyNodeIfNotExist: (nodeKey: string) => void;

                                      method deleteId

                                      deleteId: (id: string) => void;

                                        method flatten

                                        flatten: () => Array<FlatTreeNode>;

                                          method getNodes

                                          getNodes: () => { [id: string]: string[] };

                                            method getObject

                                            getObject: () => { rootIds: string[]; nodes: { [id: string]: string[] } };

                                              method getRootIds

                                              getRootIds: () => string[];

                                                method initNodes

                                                initNodes: () => void;

                                                  method initRootIds

                                                  initRootIds: () => void;

                                                    method insertIdAfterId

                                                    insertIdAfterId: (belowId: string, insertId: string) => void;

                                                      method insertIdBeforeId

                                                      insertIdBeforeId: (beforeId: string, insertId: string) => void;

                                                        method insertIdIntoId

                                                        insertIdIntoId: (insideId: string, insertId: string) => void;

                                                          method insertIdIntoNode

                                                          insertIdIntoNode: (nodeKey: string, id: string, position?: number) => void;

                                                            method insertIdIntoRoot

                                                            insertIdIntoRoot: (id: string, position?: number) => void;

                                                              method moveIdAfterId

                                                              moveIdAfterId: (moveId: string, afterId: string) => void;

                                                                method moveIdBeforeId

                                                                moveIdBeforeId: (moveId: string, beforeId: string) => void;

                                                                  method moveIdIntoId

                                                                  moveIdIntoId: (moveId: string, insideId: string, atStart?: boolean) => void;

                                                                    method swapRootIdWithRootId

                                                                    swapRootIdWithRootId: (rootId: string, withRootId: string) => void;

                                                                      method swapRootPositionWithRootPosition

                                                                      swapRootPositionWithRootPosition: (
                                                                      swapRootPosition: number,
                                                                      withRootPosition: number
                                                                      ) => void;

                                                                        method toObject

                                                                        toObject: () => { rootIds: string[]; nodes: { [id: string]: string[] } };

                                                                          class PriorityQueue

                                                                          class PriorityQueue<T> {}

                                                                            constructor

                                                                            constructor(compareFunction?: util.ICompareFunction<T>);
                                                                            • Creates an empty priority queue. In a priority queue each element is associated with a "priority", elements are dequeued in highest-priority-first order (the elements with the highest priority are dequeued first). Priority Queues are implemented as heaps. If the inserted elements are custom objects a compare function must be provided, otherwise the <=, === and >= operators are used to compare object priority. function compare(a, b) { if (a is less than b by some ordering criterion) { return -1; } if (a is greater than b by the ordering criterion) { return 1; } // a must be equal to b return 0; }

                                                                              Parameter compareFunction

                                                                              optional function used to compare two element priorities. Must return a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

                                                                            method add

                                                                            add: (element: T) => boolean;
                                                                            • Inserts the specified element into this priority queue.

                                                                              Parameter element

                                                                              the element to insert. {boolean} true if the element was inserted, or false if it is undefined.

                                                                            method clear

                                                                            clear: () => void;
                                                                            • Removes all of the elements from this priority queue.

                                                                            method contains

                                                                            contains: (element: T) => boolean;
                                                                            • Returns true if this priority queue contains the specified element.

                                                                              Parameter element

                                                                              element to search for. {boolean} true if this priority queue contains the specified element, false otherwise.

                                                                            method dequeue

                                                                            dequeue: () => T | undefined;
                                                                            • Retrieves and removes the highest priority element of this queue. {*} the the highest priority element of this queue, or undefined if this queue is empty.

                                                                            method enqueue

                                                                            enqueue: (element: T) => boolean;
                                                                            • Inserts the specified element into this priority queue.

                                                                              Parameter element

                                                                              the element to insert. {boolean} true if the element was inserted, or false if it is undefined.

                                                                            method forEach

                                                                            forEach: (callback: util.ILoopFunction<T>) => void;
                                                                            • Executes the provided function once for each element present in this queue in no particular order.

                                                                              Parameter callback

                                                                              function to execute, it is invoked with one argument: the element value, to break the iteration you can optionally return false.

                                                                            method isEmpty

                                                                            isEmpty: () => boolean;
                                                                            • Checks if this priority queue is empty. {boolean} true if and only if this priority queue contains no items; false otherwise.

                                                                            method peek

                                                                            peek: () => T | undefined;
                                                                            • Retrieves, but does not remove, the highest priority element of this queue. {*} the highest priority element of this queue, or undefined if this queue is empty.

                                                                            method size

                                                                            size: () => number;
                                                                            • Returns the number of elements in this priority queue. {number} the number of elements in this priority queue.

                                                                            class Queue

                                                                            class Queue<T> {}

                                                                              constructor

                                                                              constructor();
                                                                              • Creates an empty queue. A queue is a First-In-First-Out (FIFO) data structure, the first element added to the queue will be the first one to be removed. This implementation uses a linked list as a container.

                                                                              method add

                                                                              add: (elem: T) => boolean;
                                                                              • Inserts the specified element into the end of this queue.

                                                                                Parameter elem

                                                                                the element to insert. {boolean} true if the element was inserted, or false if it is undefined.

                                                                              method clear

                                                                              clear: () => void;
                                                                              • Removes all of the elements from this queue.

                                                                              method contains

                                                                              contains: (elem: T, equalsFunction?: util.IEqualsFunction<T>) => boolean;
                                                                              • Returns true if this queue contains the specified element. If the elements inside this stack are not comparable with the === operator, a custom equals function should be provided to perform searches, the function must receive two arguments and return true if they are equal, false otherwise. Example:

                                                                                const petsAreEqualByName (pet1, pet2) { return pet1.name === pet2.name; }

                                                                                Parameter elem

                                                                                element to search for.

                                                                                Parameter equalsFunction

                                                                                optional function to check if two elements are equal. {boolean} true if this queue contains the specified element, false otherwise.

                                                                              method dequeue

                                                                              dequeue: () => T | undefined;
                                                                              • Retrieves and removes the head of this queue. {*} the head of this queue, or undefined if this queue is empty.

                                                                              method enqueue

                                                                              enqueue: (elem: T) => boolean;
                                                                              • Inserts the specified element into the end of this queue.

                                                                                Parameter elem

                                                                                the element to insert. {boolean} true if the element was inserted, or false if it is undefined.

                                                                              method forEach

                                                                              forEach: (callback: util.ILoopFunction<T>) => void;
                                                                              • Executes the provided function once for each element present in this queue in FIFO order.

                                                                                Parameter callback

                                                                                function to execute, it is invoked with one argument: the element value, to break the iteration you can optionally return false.

                                                                              method isEmpty

                                                                              isEmpty: () => boolean;
                                                                              • Checks if this queue is empty. {boolean} true if and only if this queue contains no items; false otherwise.

                                                                              method peek

                                                                              peek: () => T | undefined;
                                                                              • Retrieves, but does not remove, the head of this queue. {*} the head of this queue, or undefined if this queue is empty.

                                                                              method size

                                                                              size: () => number;
                                                                              • Returns the number of elements in this queue. {number} the number of elements in this queue.

                                                                              class Set

                                                                              class Set<T> {}

                                                                                constructor

                                                                                constructor(toStringFunction?: (item: T) => string);
                                                                                • Creates an empty set. A set is a data structure that contains no duplicate items. If the inserted elements are custom objects a function which converts elements to strings must be provided. Example:

                                                                                  function petToString(pet) { return pet.name; }

                                                                                  Parameter toStringFunction

                                                                                  optional function used to convert elements to strings. If the elements aren't strings or if toString() is not appropriate, a custom function which receives an object and returns a unique string must be provided.

                                                                                property dictionary

                                                                                protected dictionary: Dictionary<T, any>;
                                                                                • Dictionary key and value holds the elements in the set. {Object}

                                                                                method add

                                                                                add: (element: T) => boolean;
                                                                                • Adds the specified element to this set if it is not already present.

                                                                                  Parameter element

                                                                                  the element to insert. {boolean} true if this set did not already contain the specified element.

                                                                                method clear

                                                                                clear: () => void;
                                                                                • Removes all of the elements from this set.

                                                                                method contains

                                                                                contains: (element: T) => boolean;
                                                                                • Returns true if this set contains the specified element.

                                                                                  Parameter element

                                                                                  element to search for. {boolean} true if this set contains the specified element, false otherwise.

                                                                                method difference

                                                                                difference: (otherSet: Set<T>) => void;
                                                                                • Performs a difference between this and another set. Removes from this set all the values that are present in the given set.

                                                                                  Parameter otherSet

                                                                                  other set.

                                                                                method forEach

                                                                                forEach: (callback: util.ILoopFunction<T>) => void;
                                                                                • Executes the provided function once for each element present in this set.

                                                                                  Parameter callback

                                                                                  function to execute, it is invoked with one arguments: the element. To break the iteration you can optionally return false.

                                                                                method intersection

                                                                                intersection: (otherSet: Set<T>) => void;
                                                                                • Performs an intersection between this and another set. Removes all values that are not present this set and the given set.

                                                                                  Parameter otherSet

                                                                                  other set.

                                                                                method isEmpty

                                                                                isEmpty: () => boolean;
                                                                                • Returns true if this set contains no elements. {boolean} true if this set contains no elements.

                                                                                method isSubsetOf

                                                                                isSubsetOf: (otherSet: Set<T>) => boolean;
                                                                                • Checks whether the given set contains all the elements in this set.

                                                                                  Parameter otherSet

                                                                                  other set. {boolean} true if this set is a subset of the given set.

                                                                                method remove

                                                                                remove: (element: T) => boolean;
                                                                                • Removes the specified element from this set if it is present. {boolean} true if this set contained the specified element.

                                                                                method size

                                                                                size: () => number;
                                                                                • Returns the number of elements in this set. {number} the number of elements in this set.

                                                                                method toArray

                                                                                toArray: () => T[];
                                                                                • Returns an array containing all of the elements in this set in arbitrary order. {Array} an array containing all of the elements in this set.

                                                                                method toString

                                                                                toString: () => string;

                                                                                  method union

                                                                                  union: (otherSet: Set<T>) => void;
                                                                                  • Performs a union between this and another set. Adds all values from the given set to this set.

                                                                                    Parameter otherSet

                                                                                    other set.

                                                                                  class Stack

                                                                                  class Stack<T> {}

                                                                                    constructor

                                                                                    constructor();
                                                                                    • Creates an empty Stack. A Stack is a Last-In-First-Out (LIFO) data structure, the last element added to the stack will be the first one to be removed. This implementation uses a linked list as a container.

                                                                                    method add

                                                                                    add: (elem: T) => boolean;
                                                                                    • Pushes an item onto the top of this stack.

                                                                                      Parameter elem

                                                                                      the element to be pushed onto this stack. {boolean} true if the element was pushed or false if it is undefined.

                                                                                    method clear

                                                                                    clear: () => void;
                                                                                    • Removes all of the elements from this stack.

                                                                                    method contains

                                                                                    contains: (elem: T, equalsFunction?: util.IEqualsFunction<T>) => boolean;
                                                                                    • Returns true if this stack contains the specified element. If the elements inside this stack are not comparable with the === operator, a custom equals function should be provided to perform searches, the function must receive two arguments and return true if they are equal, false otherwise. Example:

                                                                                      const petsAreEqualByName (pet1, pet2) { return pet1.name === pet2.name; }

                                                                                      Parameter elem

                                                                                      element to search for.

                                                                                      Parameter equalsFunction

                                                                                      optional function to check if two elements are equal. {boolean} true if this stack contains the specified element, false otherwise.

                                                                                    method forEach

                                                                                    forEach: (callback: util.ILoopFunction<T>) => void;
                                                                                    • Executes the provided function once for each element present in this stack in LIFO order.

                                                                                      Parameter callback

                                                                                      function to execute, it is invoked with one argument: the element value, to break the iteration you can optionally return false.

                                                                                    method isEmpty

                                                                                    isEmpty: () => boolean;
                                                                                    • Checks if this stack is empty. {boolean} true if and only if this stack contains no items; false otherwise.

                                                                                    method peek

                                                                                    peek: () => T | undefined;
                                                                                    • Looks at the object at the top of this stack without removing it from the stack. {*} the object at the top of this stack or undefined if the stack is empty.

                                                                                    method pop

                                                                                    pop: () => T | undefined;
                                                                                    • Removes the object at the top of this stack and returns that object. {*} the object at the top of this stack or undefined if the stack is empty.

                                                                                    method push

                                                                                    push: (elem: T) => boolean;
                                                                                    • Pushes an item onto the top of this stack.

                                                                                      Parameter elem

                                                                                      the element to be pushed onto this stack. {boolean} true if the element was pushed or false if it is undefined.

                                                                                    method size

                                                                                    size: () => number;
                                                                                    • Returns the number of elements in this stack. {number} the number of elements in this stack.

                                                                                    Package Files (15)

                                                                                    Dependencies (0)

                                                                                    No dependencies.

                                                                                    Dev Dependencies (25)

                                                                                    Peer Dependencies (0)

                                                                                    No peer dependencies.

                                                                                    Badge

                                                                                    To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                    You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/typescript-collections.

                                                                                    • Markdown
                                                                                      [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/typescript-collections)
                                                                                    • HTML
                                                                                      <a href="https://www.jsdocs.io/package/typescript-collections"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>