A collection of nodes from a given graph. All nodes have a common node type. If the nodes can be of any node type, the common type is BaseNode.

Type Parameters

Indexable

  • [index: number]: N

    Access the node at the given index.

Accessors

  • get totalDegree(): number
  • Returns the total degree of all nodes in the collection. Loop edges are counted twice.

    Returns number

    the total degree of this collection.

  • get totalDegreeWithoutLoops(): number
  • Returns the total degree of all nodes in the collection. Loop edges are not counted.

    Returns number

    the total degree of this collection, excluding loop edges.

Methods

  • Access the node at the given index. This is similar to indexing, but has undefined in the return type.

    Parameters

    • index: number

      The index of the node to access.

    Returns undefined | N

    The node at the given index, or undefined if it does not exist.

  • Returns whether all nodes in the collection satisfy the provided function. Returns true for an empty collection.

    Parameters

    • f: ((ele: N, i: number, eles: this) => boolean)

      The function to test each node. ele - The current element, i - The index of the current element, eles - The collection of elements being iterated.

        • (ele, i, eles): boolean
        • Parameters

          • ele: N
          • i: number
          • eles: this

          Returns boolean

    Returns boolean

    Whether all nodes in the collection satisfy the function.

  • Returns whether all nodes in the collection satisfy the provided function. Returns true for an empty collection.

    Type Parameters

    • T

    Parameters

    • f: ((this: T, ele: N, i: number, eles: this) => boolean)

      The function to test each node. ele - The current element, i - The index of the current element, eles - The collection of elements being iterated.

        • (this, ele, i, eles): boolean
        • Parameters

          • this: T
          • ele: N
          • i: number
          • eles: this

          Returns boolean

    • thisArg: T

      The value to use as this when executing the function.

    Returns boolean

    Whether all nodes in the collection satisfy the function.

  • Changes the functionality class of the nodes. Should only be used when it is known (but not statically provable) that all nodes are compatible with the new class. If not, an error will be thrown.

    It is bad practice to try and catch the error thrown by this function. For such cases, combine NodeCollection.allAre with NodeCollection.allAs.

    Type Parameters

    Parameters

    • NodeType: Node<D2, S2, N2>

      The node type to change the functionality class into.

    • Optionalmessage: string | ((i: number) => string)

      The message to throw if the node is not compatible with the type. May also be a function that takes the index of the first incompatible node and returns a message.

    Returns NodeCollection<N2, D2, S2>

    The node collection, wrapped in the new functionality class.

    LaraFlowError if any node is not compatible with the type. This error should be seen as a logic error and not catched.

  • Returns a new collection containing only the nodes that satisfy the provided function.

    Parameters

    • f: ((ele: N, i: number, eles: this) => boolean)

      The function to test each node. ele - The current element, i - The index of the current element, eles - The collection of elements being iterated.

        • (ele, i, eles): boolean
        • Parameters

          • ele: N
          • i: number
          • eles: this

          Returns boolean

    Returns NodeCollection<N, D, S>

    A new collection containing only the nodes that satisfy the function.

  • Returns a new collection containing only the nodes that satisfy the provided function.

    Type Parameters

    • T

    Parameters

    • f: ((this: T, ele: N, i: number, eles: this) => boolean)

      The function to test each node. ele - The current element, i - The index of the current element, eles - The collection of elements being iterated.

        • (this, ele, i, eles): boolean
        • Parameters

          • this: T
          • ele: N
          • i: number
          • eles: this

          Returns boolean

    • thisArg: T

      The value to use as this when executing the function.

    Returns NodeCollection<N, D, S>

    A new collection containing only the nodes that satisfy the function.

  • Executes the provided function once for each node in the collection.

    Unline the analogous cytoscape method, this method does not support exiting early by returning false, due to the fact that a return false; would not be clear and intuitive for someone reading the code. As such, this function follows the behavior of the Array.prototype.forEach method.

    In the future, if that feature is really desirable, instead of returning false, the function could return an enum value that represents a control flow instruction. Until then, a for loop may be used.

    Parameters

    • f: ((ele: N, i: number, eles: this) => void)

      The function to execute for each node. ele - The current element, i - The index of the current element, eles - The collection of elements being iterated.

        • (ele, i, eles): void
        • Parameters

          • ele: N
          • i: number
          • eles: this

          Returns void

    Returns void

  • Executes the provided function once for each node in the collection.

    Unline the analogous cytoscape method, this method does not support exiting early by returning false, due to the fact that a return false; would not be clear and intuitive for someone reading the code. As such, this function follows the behavior of the Array.prototype.forEach method.

    In the future, if that feature is really desirable, instead of returning false, the function could return an enum value that represents a control flow instruction. Until then, a for loop may be used.

    Type Parameters

    • T

    Parameters

    • f: ((this: T, ele: N, i: number, eles: this) => void)

      The function to execute for each node. ele - The current element, i - The index of the current element, eles - The collection of elements being iterated.

        • (this, ele, i, eles): void
        • Parameters

          • this: T
          • ele: N
          • i: number
          • eles: this

          Returns void

    • thisArg: T

      The value to use as this when executing the function.

    Returns void

  • Find the maximum value in a collection.

    Parameters

    • f: ((ele: N, i: number, eles: this) => number)

      The function that returns the value to compare. ele - The current element, i - The index of the current element, eles - The collection of elements being iterated.

        • (ele, i, eles): number
        • Parameters

          • ele: N
          • i: number
          • eles: this

          Returns number

    Returns undefined | {
        element: N;
        value: number;
    }

    An object with the maximum element and its value, or undefined if the collection is empty.

  • Find the maximum value in a collection.

    Type Parameters

    • T

    Parameters

    • f: ((this: T, ele: N, i: number, eles: this) => number)

      The function that returns the value to compare. ele - The current element, i - The index of the current element, eles - The collection of elements being iterated.

        • (this, ele, i, eles): number
        • Parameters

          • this: T
          • ele: N
          • i: number
          • eles: this

          Returns number

    • thisArg: T

      The value to use as this when executing the function.

    Returns undefined | {
        element: N;
        value: number;
    }

    An object with the maximum element and its value, or undefined if the collection is empty.

  • Find the minimum value in a collection.

    Parameters

    • f: ((ele: N, i: number, eles: this) => number)

      The function that returns the value to compare. ele - The current element, i - The index of the current element, eles - The collection of elements being iterated.

        • (ele, i, eles): number
        • Parameters

          • ele: N
          • i: number
          • eles: this

          Returns number

    Returns undefined | {
        element: N;
        value: number;
    }

    An object with the minimum element and its value, or undefined if the collection is empty.

  • Find the minimum value in a collection.

    Type Parameters

    • T

    Parameters

    • f: ((this: T, ele: N, i: number, eles: this) => number)

      The function that returns the value to compare. ele - The current element, i - The index of the current element, eles - The collection of elements being iterated.

        • (this, ele, i, eles): number
        • Parameters

          • this: T
          • ele: N
          • i: number
          • eles: this

          Returns number

    • thisArg: T

      The value to use as this when executing the function.

    Returns undefined | {
        element: N;
        value: number;
    }

    An object with the minimum element and its value, or undefined if the collection is empty.

  • Get a subset of the elements in the collection based on specified indices.

    Parameters

    • Optionalstart: number

      An integer that specifies where to start the selection. If omitted, the first element, with an index of 0, will be selected. Use negative numbers to select from the end of an array.

    • Optionalend: number

      An integer that specifies where to end the selection. If omitted, all elements from the start position and to the end of the array will be selected. Use negative numbers to select from the end of an array.

    Returns NodeCollection<N, D, S>

    A new collection containing the selected elements.

  • Returns whether any node in the collection satisfies the provided function. Returns false for an empty collection.

    Parameters

    • f: ((ele: N, i: number, eles: this) => boolean)

      The function to test each node. ele - The current element, i - The index of the current element, eles - The collection of elements being iterated.

        • (ele, i, eles): boolean
        • Parameters

          • ele: N
          • i: number
          • eles: this

          Returns boolean

    Returns boolean

    Whether any node in the collection satisfies the function.

  • Returns whether any node in the collection satisfies the provided function. Returns false for an empty collection.

    Type Parameters

    • T

    Parameters

    • f: ((this: T, ele: N, i: number, eles: this) => boolean)

      The function to test each node. ele - The current element, i - The index of the current element, eles - The collection of elements being iterated.

        • (this, ele, i, eles): boolean
        • Parameters

          • this: T
          • ele: N
          • i: number
          • eles: this

          Returns boolean

    • thisArg: T

      The value to use as this when executing the function.

    Returns boolean

    Whether any node in the collection satisfies the function.

  • Returns a collection with the elements sorted according to the given comparison function.

    Regarding the return value of the comparison function:

    • A negative value indicates that a should come before b.
    • A positive value indicates that a should come after b.
    • Zero or NaN indicates that a and b are considered equal.

    Parameters

    • f: ((a: N, b: N) => number)

      The comparison function to use for sorting.

        • (a, b): number
        • Parameters

          Returns number

    Returns NodeCollection<N, D, S>

    A new collection with the elements sorted.