binmap
binmap
is a Map
implementation compatible to the Built-in Map but guaranteeing the keys to be ordered.
The constructor has an optional options object and the class has a member function between
for iterating between two boundary keys.
BinMap
instances are convertible to and from built-in Maps and Arrays (of sub-arrays).
Functions
Constructor
The constructor works like the built-in Map in that it can optionally take an iterable of key-value pairs (as individual arrays), but can also have an extra optional options object which can contain a comparison function cmp
with the same semantics as the custom sort
comparator.
// Custom comparator; ;// or;
betwen
between( { ... } )
returns an IterableIterator between two boundary keys. The options object can contain:
- Either an
lt
(less than) or anle
(less than or equal to). - Either a
gt
(greater than) or age
(greater than or equal to). reverse
being a boolean (defaults tofalse
), which iftrue
returns an iterator from the end to the beginning of the span.
There are two magic values for lt
, le
, gt
and ge
which is BinMap.min
and BinMap.max
which represents the lowest/highest possible values. These are also the default, so an empty between( { } )
(or just between( )
) iterates the whole map.
; Array.from bm.between // -> [ [ "c", 3 ], [ "d", 4 ] ] Array.from bm.between // -> [ [ "d", 4 ], [ "c", 3 ] ]