You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
BTree includes a lattice of interface types representing subsets of BTree's interface. I would encourage other authors of map/dictionary/tree/hashtable types to utilize these interfaces. These interfaces can be divided along three dimensions:
148
+
BTree includes a [lattice of interface types](https://github.com/qwertie/btree-typescript/blob/master/interfaces.d.ts) representing subsets of BTree's interface. I would encourage other authors of map/dictionary/tree/hashtable types to utilize these interfaces. These interfaces can be divided along three dimensions:
149
149
150
150
### 1. Read/write access ###
151
151
@@ -160,6 +160,8 @@ I have defined several kinds of interfaces along the read/write access dimension
160
160
161
161
The `Sorted` interfaces extend the non-sorted interfaces with queries that only a sorted collection can perform efficiently, such as `minKey()` and `nextHigherKey(k)`. At minimum, sorted interfaces add methods `minKey`, `maxKey`, `nextHigherKey`, `nextLowerKey`, and `forRange`, plus iterators that return keys/values/pairs in sorted order and accept a `firstKey` parameter to control the starting point of iteration.
162
162
163
+
**Note:** in sorted-btree ≤ v1.7.x, these interfaces have methods `nextHigherKey(key: K)` and `nextLowerKey(key: K)` which should be `nextHigherKey(key: K|undefined)` and `nextLowerKey(key: K|undefined)`. These signatures are changed in the next version.
164
+
163
165
### 3. Set versus map ###
164
166
165
167
A map is a collection of keys with values, while a set is a collection of keys without values.
@@ -168,7 +170,7 @@ For the most part, each `Set` interface is a subset of the corresponding `Map` i
168
170
169
171
### List of interfaces ###
170
172
171
-
All of these interfaces use `any` as the default type of `K` and `V`.
173
+
All of these [interfaces](https://github.com/qwertie/btree-typescript/blob/master/interfaces.d.ts) use `any` as the default type of `K` and `V`.
172
174
173
175
-`ISetSource<K>`
174
176
-`ISetSink<K>`
@@ -185,9 +187,9 @@ All of these interfaces use `any` as the default type of `K` and `V`.
If the lattice were complete there would be 16 interfaces (4*2*2). In fact there are only 14 interfaces because `ISortedMapSink<K,V>` and `ISortedSetSink<K, V>` don't exist, because sorted sinks are indistinguishable from unsorted sinks.
190
+
If the lattice were complete there would be 16 interfaces (`4*2*2`). In fact there are only 14 interfaces because `ISortedMapSink<K,V>` and `ISortedSetSink<K, V>` don't exist, because sorted sinks are indistinguishable from unsorted sinks.
189
191
190
-
`BTree<K,V>` implements all of these interfaces except `ISetSink<K>`, `ISet<K>`, and `ISortedSet<K>`.
192
+
`BTree<K,V>` implements all of these interfaces except `ISetSink<K>`, `ISet<K>`, and `ISortedSet<K>`. However, `BTree<K,V>` may be _compatible_ with these interfaces even if TypeScript doesn't realize it. Therefore, if `V` includes `undefined`, the `BTree<K,V>.asSet` property is provided to cast the `BTree` to a set type. The `asSet` property returns the same `BTree` as type `ISortedSet<K>` (which is assignable to `ISetSink<K>`, `ISet<K>` and `ISortedSetSource<K>`).
0 commit comments