@unikue/ts-multi-map
    Preparing search index...

    Class ReadonlyRangeMap<V>

    Readonly map with entries that contains a range key and a value

    David Hsing

    Type Parameters

    • V

    Implements

    • Omit<
          ReadonlyMap<RangeMapKey, V>,
          "forEach" | "get" | "has" | "entries" | "keys" | "values",
      >
    Index

    Constructors

    • Construct a readonly range map instance

      Type Parameters

      • V

      Parameters

      • Optionalentries: [RangeMapKey | [number, number] | [number, number, boolean, boolean], V][]

        the map entries

      • validation: boolean = true

        whether to compare the ranges to all the ranges previously, to determine if there are any conflicts

      Returns ReadonlyRangeMap<V>

      const map = new ReadonlyRangeMap([
      [[1, 30], 'green'],
      [[30, 60], 'blue'],
      [[60, 90], 'orange'],
      [[90, 100, true, true], 'red']
      ]);

    Accessors

    • get "[toStringTag]"(): string

      Returns the string representation of the map identifier ('ReadonlyRangeMap')

      Returns string

      the string representation of the map identifier

    • get size(): number

      Returns the size of map

      Returns number

      the size of map

    Methods

    • Response for returning the list of key/value to iterate

      Returns IterableIterator<[RangeMapKey, V]>

      for (const [key, value] of map) {
      console.log(value);
      }
    • Returns the key/value entries of the map

      Returns [RangeMapKey, V][]

      the key/value entries of the map

    • Processes each entry in the map

      Parameters

      • callback: (value?: V, key?: RangeMapKey) => void

        a callback function that processes each entry

      • OptionalthisArg: any

        any instance to retrieve 'this' reference in the callback function

      Returns void

      map.forEach((value, key) => {
      console.log(value);
      });
    • Processes each entry in the map with breakable capability

      Parameters

      • callback: (value?: V, key?: RangeMapKey) => boolean

        a callback function that processes each entry. Returning false indicates to break the map iteration

      • OptionalthisArg: any

        any instance to retrieve 'this' reference in the callback function

      Returns void

      map.forEachBreakable((value, key) => {
      return true;
      });
    • Processes each entry in the map with index capability

      Parameters

      • callback: (value?: V, key?: RangeMapKey, index?: number) => void

        a callback function that processes each entry

      • OptionalthisArg: any

        any instance to retrieve 'this' reference in the callback function

      Returns void

      map.forEachIndexing((value, key, index) => {
      console.log(index);
      });
    • Returns the value of the given key

      Parameters

      • key: RangeMapKey | [number, number] | [number, number, boolean, boolean]

        the key to retrieve

      • Optionaldefaults: V

        the default value if not found

      Returns undefined | V

      the value of the given key

      const map = ReadonlyRangeMap.of([
      [[1, 50, true, true], 'white'],
      [[51, 100, false, true], 'black']
      ]);
      map.get([1, 50, true, true]); // 'white'
      map.get([51, 100, false, true]); // 'black'
    • Returns the value that associated to the number, by determining which bound contains the given number

      Parameters

      • digit: number

        the number to retrieve

      • Optionaldefaults: V

        the default value if not found

      Returns undefined | V

      the value that associated to the number, by determining which bound contains the given number

      const map = ReadonlyRangeMap.of([
      [[1, 50, true, true], 'white'],
      [[51, 100, false, true], 'black']
      ]);
      map.get(25); // 'white'
      map.get(200); // undefined
    • Returns whether the map contains all the given keys

      Parameters

      • keys: (RangeMapKey | [number, number] | [number, number, boolean, boolean])[]

        the keys to check

      Returns boolean

      whether the map contains all the given keys

      map.hasAllKeys([[1, 50], [51, 100]]);
      
    • Returns whether the map contains all the given values, matching exactly

      Parameters

      • values: V[]

        the values to check

      Returns boolean

      whether the map contains all the given values, matching exactly

      map.hasAllValues(['red', 'green', 'blue']);
      
    • Returns whether the map contains any of the given keys

      Parameters

      • keys: (RangeMapKey | [number, number] | [number, number, boolean, boolean])[]

        the keys to check

      Returns boolean

      whether the map contains any of the given keys

      const map = ReadonlyRangeMap.of([
      [[1, 50, true, true], 'white'],
      [[51, 100, false, true], 'black']
      ]);
      map.hasAnyKeys([[1, 50, true, true], [20, 60]]); // true
    • Returns whether the map contains any of the given values

      Parameters

      • values: V[]

        the values to check

      Returns boolean

      whether the map contains any of the given values

      const map = ReadonlyRangeMap.of([
      [[1, 50, true, true], 'white'],
      [[51, 100, false, true], 'black']
      ]);
      map.hasAnyValues(['red', 'black']); // true
      map.hasAnyValues(['top', 'right']); // false
    • Returns whether the map contains the given key

      Parameters

      • key: RangeMapKey | [number, number] | [number, number, boolean, boolean]

        the key to check

      Returns boolean

      whether the map contains the given key

      map.hasKey([1, 30]);
      
    • Returns whether the map contains the given key/value pair

      Parameters

      • key: RangeMapKey | [number, number] | [number, number, boolean, boolean]

        the key to check

      • value: V

        the value to check

      Returns boolean

      whether the map contains the given key/value pair

      const map = ReadonlyRangeMap.of([
      [[1, 50], 'white']
      ]);
      map.hasKeyValue([1, 50], 'white'); // true
      map.hasKeyValue([1, 50], 'black'); // false
    • Returns whether any entries of the map that contains the given values

      Parameters

      • value: V

        the value to check

      Returns boolean

      whether any entries of the map that contains the given values

      const map = ReadonlyRangeMap.of([
      [[1, 50, true, true], 'white'],
      [[51, 100, false, true], 'black']
      ]);
      map.hasValue('white'); // true
      map.hasValue('blue'); // false
    • Returns whether the map is empty

      Returns boolean

      whether the map is empty

    • Returns whether the map is not empty

      Returns boolean

      whether the map is not empty

    • Returns the string representation of the map elements

      Returns string

      the string representation of the map elements

      const map = ReadonlyRangeMap.of([
      [[1, 50, true, true], 'white'],
      [[51, 100, false, true], 'black']
      ]);
      console.log(map.toString()); // '[start:1,end:50,startInclusive:true,endInclusive:true]:white;[start:51,end:100,startInclusive:false,endInclusive:true]:black'
    • Returns the value array of the map

      Returns V[]

      the value array of the map

    • Construct a readonly range map instance

      Type Parameters

      • V

      Parameters

      • Optionalentries: [RangeMapKey | [number, number] | [number, number, boolean, boolean], V][]

        the map entries

      • validation: boolean = true

        whether to compare the ranges to all the ranges previously, to determine if there are any conflicts

      Returns ReadonlyRangeMap<V>

      a readonly multi value map instance

      const map = ReadonlyRangeMap.of([
      [[1, 30], 'green'],
      [[30, 60], 'blue'],
      [[60, 90], 'orange'],
      [[90, 100, true, true], 'red']
      ]);