diff --git a/interfaces.d.ts b/interfaces.d.ts index 9f1e001..e55ee38 100644 --- a/interfaces.d.ts +++ b/interfaces.d.ts @@ -84,10 +84,12 @@ export interface ISortedSetSource extends ISetSource minKey(): K | undefined; /** Gets the highest key in the collection. */ maxKey(): K | undefined; - /** Returns the next key larger than the specified key (or undefined if there is none) */ - nextHigherKey(key: K): K|undefined; - /** Returns the next key smaller than the specified key (or undefined if there is none) */ - nextLowerKey(key: K): K|undefined; + /** Returns the next key larger than the specified key (or undefined if there is none). + * Also, nextHigherKey(undefined) returns the lowest key. */ + nextHigherKey(key?: K): K|undefined; + /** Returns the next key smaller than the specified key (or undefined if there is none). + * Also, nextLowerKey(undefined) returns the highest key. */ + nextLowerKey(key?: K): K|undefined; /** Calls `callback` on the specified range of keys, in ascending order by key. * @param low The first key scanned will be greater than or equal to `low`. * @param high Scanning stops when a key larger than this is reached. @@ -109,10 +111,12 @@ export interface ISortedSetSource extends ISetSource /** An data source that provides read-only access to items in sorted order. */ export interface ISortedMapSource extends IMapSource, ISortedSetSource { - /** Returns the next pair whose key is larger than the specified key (or undefined if there is none) */ - nextHigherPair(key: K): [K,V]|undefined; - /** Returns the next pair whose key is smaller than the specified key (or undefined if there is none) */ - nextLowerPair(key: K): [K,V]|undefined; + /** Returns the next pair whose key is larger than the specified key (or undefined + * if there is none). If key === undefined, this function returns the lowest pair. */ + nextHigherPair(key?: K): [K,V]|undefined; + /** Returns the next pair whose key is smaller than the specified key (or undefined + * if there is none). If key === undefined, this function returns the highest pair. */ + nextLowerPair(key?: K): [K,V]|undefined; /** Builds an array of pairs from the specified range of keys, sorted by key. * Each returned pair is also an array: pair[0] is the key, pair[1] is the value. * @param low The first key in the array will be greater than or equal to `low`. diff --git a/package.json b/package.json index ce50153..c5c6845 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sorted-btree", - "version": "1.7.0", + "version": "1.8.0", "description": "A sorted list of key-value pairs in a fast, typed in-memory B+ tree with a powerful API.", "main": "b+tree.js", "typings": "b+tree", diff --git a/readme.md b/readme.md index dc0971a..841ce6c 100644 --- a/readme.md +++ b/readme.md @@ -9,10 +9,10 @@ This is a fast B+ tree implementation, largely compatible with the standard Map, Use `npm install sorted-btree` in a terminal to install it in your npm-based project. -Ukraine -------- +Ukraine is still under attack +----------------------------- -I'm writing this on the one-month anniversary of the full-scale invasion of Ukraine. +I'm writing this on March 24, 2022: the one-month anniversary of the full-scale invasion of Ukraine. ![Mariupol](http://david.loyc.net/misc/ukraine/Mariupol-from-above.webp) @@ -28,7 +28,7 @@ Without electricity, reports from Mariupol have been limited, but certainly ther ![Mariupol apartment bombed](http://david.loyc.net/misc/ukraine/Mariupol-explosion.webp) -Here you can see the famous theatre labeled "Children" in huge letters, which Russia bombed anyway. +Here you can see the famous Donetsk Academic Regional Drama Theatre, labeled "дети" ("children") in huge letters, which held over 1,000 civilians. Russia bombed it anyway. ![Mariupol theatre](http://david.loyc.net/misc/ukraine/Mariupol-theatre-children.webp) ![Mariupol theatre before](http://david.loyc.net/misc/ukraine/Mariupol-theatre-children-before.jpg) @@ -48,7 +48,7 @@ Or in these other places... ![Kharkiv](http://david.loyc.net/misc/ukraine/Kharkiv-firefighters-rubble.webp) ![Kharkiv](http://david.loyc.net/misc/ukraine/Kharkiv-two-dead.webp) -What's that? You just wanted a B+ tree? Fair enough. I hope it meets your needs. +What's that? You just wanted a B+ tree? Well, you're in for a treat. Features -------- @@ -418,6 +418,17 @@ Benchmarks (in milliseconds for integer keys/values) Version history --------------- +### v1.8.0 ### + +- Argument of `ISortedSetSource.nextHigherKey(key: K)` changed to `key?: K` +- Argument of `ISortedSetSource.nextLowerKey(key: K)` changed to `key?: K` +- Argument of `ISortedMapSource.nextHigherPair(key: K)` changed to `key?: K` +- Argument of `ISortedMapSource.nextLowerPair(key: K)` changed to `key?: K` + +### v1.7.0 ### + +- Added `asSet` method, defined as follows: `asSet(btree: BTree): undefined extends V ? ISortedSet : unknown { return btree as any; }` + ### v1.6.2 ### - Bug fixes: two rare situations were discovered in which shared nodes could fail to be marked as shared, and as a result, mutations could affect copies that should have been completely separate.