Options
All
  • Public
  • Public/Protected
  • All
Menu

Class RadixNodeEdges<T>

The set of edges from a RadixNode to its children. Maintains a single invariant:

  • Only a single edge label can start with a particular character

Because of that invariant, children are indexed by the first character (code) of their edge label, which makes finding the edge that shares a prefix with a given key an O(1) lookup keyed by a single char code -- never a hash of the whole label, and never a scan of the children.

The backing Map is allocated lazily: leaf nodes (the majority in most trees) hold no Map at all. Each slot stores the full edge label alongside its child node, so no second map is needed to recover the label from the first character.

Type parameters

  • T

Hierarchy

  • RadixNodeEdges

Index

Constructors

Properties

Accessors

Methods

Constructors

constructor

  • example

    const rne = new RadixNodeEdges([ ["aaa", new RadixNode()], ["bbb", new RadixNode()] ]);

    Parameters

    • Optional knpairs: Array<[string, RadixNode<T>]>

    Returns RadixNodeEdges

Properties

m

m: Map<number, [string, RadixNode<T>]> | undefined

Accessors

size

  • get size(): number
  • get the number of edges to other RadixNodes

    Returns number

Methods

delete

  • delete(k: string): boolean
  • Delete an edge label from this RadixNodeEdges. Cannot corrupt the state of the edges list.

    Parameters

    • k: string

    Returns boolean

entries

  • entries(): IterableIterator<[string, RadixNode<T>]>
  • A generator over all [edgeLabel, node] pairs.

    Returns IterableIterator<[string, RadixNode<T>]>

findKeyHavingSharedPrefix

  • findKeyHavingSharedPrefix(prefix: string): string | undefined
  • Parameters

    • prefix: string

    Returns string | undefined

    either the matching edge label or undefined if no matching label

get

  • Get the RadixNode associated to an edge label k

    Parameters

    • k: string

    Returns RadixNode<T> | undefined

getChild

  • getChild(key: string, start?: number): [string, RadixNode<T>] | undefined
  • Find the edge label sharing a prefix with key, comparing from key[start] onwards.

    Parameters

    • key: string

      the key whose first (unconsumed) character selects the edge

    • Default value start: number = 0

      the index in key at which the relevant character begins

    Returns [string, RadixNode<T>] | undefined

    the [edgeLabel, childNode] pair for the matching edge, or undefined

has

  • has(k: string): boolean
  • Check if there is an edge associated to a particular label.

    Parameters

    • k: string

    Returns boolean

keys

  • keys(): IterableIterator<string>
  • A generator over all edge labels.

    Returns IterableIterator<string>

set

  • Set an association between an edge label k and a RadixNode. Because edges are keyed by first character, any existing edge starting with the same character is transparently replaced -- which is exactly the invariant we want to maintain.

    Parameters

    Returns void

values

  • A generator over all child RadixNodes.

    Returns IterableIterator<RadixNode<T>>

Generated using TypeDoc