aberdeen 1.0.7 → 1.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/aberdeen.d.ts +2 -2
- package/dist/aberdeen.js +35 -12
- package/dist/aberdeen.js.map +4 -4
- package/dist/helpers/reverseSortedSet.d.ts +8 -3
- package/dist-min/aberdeen.js +5 -5
- package/dist-min/aberdeen.js.map +4 -4
- package/html-to-aberdeen +354 -0
- package/package.json +1 -1
- package/src/aberdeen.ts +63 -19
- package/src/helpers/reverseSortedSet.ts +34 -31
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
// Meta-data is saved in-place on ReverseSorted items.
|
|
2
|
+
// - Items in the set should indicate they support {[ptr: ReverseSortedSetPointer]: SELF}
|
|
3
|
+
export type ReverseSortedSetPointer = symbol;
|
|
4
|
+
|
|
5
|
+
// ReverseSortedSet saves the skip links for all required levels on the object itself
|
|
6
|
+
type SkipItem<T> = { [idx: ReverseSortedSetPointer]: T };
|
|
2
7
|
|
|
3
8
|
/**
|
|
4
9
|
* A set-like collection of objects that can do iteration sorted by a specified index property.
|
|
@@ -8,11 +13,11 @@ type Item<T> = T & { [idx: symbol]: Item<T> };
|
|
|
8
13
|
* It's implemented as a skiplist, maintaining all meta-data as part of the objects that it
|
|
9
14
|
* is tracking, for performance.
|
|
10
15
|
*/
|
|
11
|
-
export class ReverseSortedSet<T extends
|
|
16
|
+
export class ReverseSortedSet<T extends SkipItem<T>, KeyPropT extends keyof T> {
|
|
12
17
|
// A fake item, that is not actually T, but *does* contain symbols pointing at the first item for each level.
|
|
13
|
-
private tail:
|
|
18
|
+
private tail: SkipItem<T>;
|
|
14
19
|
// As every SkipList instance has its own symbols, an object can be included in more than one SkipList.
|
|
15
|
-
private symbols:
|
|
20
|
+
private symbols: ReverseSortedSetPointer[];
|
|
16
21
|
|
|
17
22
|
/**
|
|
18
23
|
* Create an empty SortedSet.
|
|
@@ -21,8 +26,8 @@ export class ReverseSortedSet<T extends object> {
|
|
|
21
26
|
* using `<` will be done on this property, so it should probably be a number or a string (or something that
|
|
22
27
|
* has a useful toString-conversion).
|
|
23
28
|
*/
|
|
24
|
-
constructor(private keyProp:
|
|
25
|
-
this.tail = {} as
|
|
29
|
+
constructor(private keyProp: KeyPropT) {
|
|
30
|
+
this.tail = {} as SkipItem<T>;
|
|
26
31
|
this.symbols = [Symbol(0)];
|
|
27
32
|
}
|
|
28
33
|
|
|
@@ -54,15 +59,15 @@ export class ReverseSortedSet<T extends object> {
|
|
|
54
59
|
const keyProp = this.keyProp;
|
|
55
60
|
const key = item[keyProp];
|
|
56
61
|
|
|
57
|
-
|
|
58
|
-
let
|
|
62
|
+
// prev is always a complete T, current might be tail only contain pointers
|
|
63
|
+
let prev: T | undefined;
|
|
64
|
+
let current: SkipItem<T> = this.tail;
|
|
59
65
|
for (let l = this.symbols.length - 1; l >= 0; l--) {
|
|
60
66
|
const symbol = this.symbols[l];
|
|
61
|
-
while ((prev = current[symbol]
|
|
62
|
-
current = prev;
|
|
67
|
+
while ((prev = current[symbol]) && prev[keyProp] > key) current = prev;
|
|
63
68
|
if (l < level) {
|
|
64
|
-
(item as
|
|
65
|
-
|
|
69
|
+
(item as SkipItem<T>)[symbol] = current[symbol];
|
|
70
|
+
current[symbol] = item;
|
|
66
71
|
}
|
|
67
72
|
}
|
|
68
73
|
|
|
@@ -106,13 +111,15 @@ export class ReverseSortedSet<T extends object> {
|
|
|
106
111
|
*
|
|
107
112
|
* Time complexity: O(log n)
|
|
108
113
|
*/
|
|
109
|
-
get(indexValue:
|
|
114
|
+
get(indexValue: T[KeyPropT]): T | undefined {
|
|
110
115
|
const keyProp = this.keyProp;
|
|
111
|
-
|
|
112
|
-
|
|
116
|
+
|
|
117
|
+
// prev is always a complete T, current might be tail only contain pointers
|
|
118
|
+
let prev: T | undefined;
|
|
119
|
+
let current: SkipItem<T> = this.tail;
|
|
113
120
|
for (let l = this.symbols.length - 1; l >= 0; l--) {
|
|
114
121
|
const symbol = this.symbols[l];
|
|
115
|
-
while ((prev = current[symbol]
|
|
122
|
+
while ((prev = current[symbol]) && prev[keyProp] > indexValue)
|
|
116
123
|
current = prev;
|
|
117
124
|
}
|
|
118
125
|
return current[this.symbols[0]]?.[keyProp] === indexValue
|
|
@@ -125,10 +132,10 @@ export class ReverseSortedSet<T extends object> {
|
|
|
125
132
|
*/
|
|
126
133
|
*[Symbol.iterator](): IterableIterator<T> {
|
|
127
134
|
const symbol = this.symbols[0];
|
|
128
|
-
let node
|
|
135
|
+
let node = this.tail[symbol];
|
|
129
136
|
while (node) {
|
|
130
137
|
yield node;
|
|
131
|
-
node = node[symbol]
|
|
138
|
+
node = node[symbol];
|
|
132
139
|
}
|
|
133
140
|
}
|
|
134
141
|
|
|
@@ -140,7 +147,7 @@ export class ReverseSortedSet<T extends object> {
|
|
|
140
147
|
* Time complexity: O(1)
|
|
141
148
|
*/
|
|
142
149
|
prev(item: T): T | undefined {
|
|
143
|
-
return
|
|
150
|
+
return item[this.symbols[0]];
|
|
144
151
|
}
|
|
145
152
|
|
|
146
153
|
/**
|
|
@@ -156,19 +163,15 @@ export class ReverseSortedSet<T extends object> {
|
|
|
156
163
|
const keyProp = this.keyProp;
|
|
157
164
|
const prop = item[keyProp];
|
|
158
165
|
|
|
159
|
-
|
|
160
|
-
let
|
|
161
|
-
|
|
166
|
+
// prev is always a complete T, current might be tail only contain pointers
|
|
167
|
+
let prev: T | undefined;
|
|
168
|
+
let current: SkipItem<T> = this.tail;
|
|
162
169
|
for (let l = this.symbols.length - 1; l >= 0; l--) {
|
|
163
170
|
const symbol = this.symbols[l];
|
|
164
|
-
while (
|
|
165
|
-
(prev = current[symbol] as Item<T>) &&
|
|
166
|
-
prev[keyProp] >= prop &&
|
|
167
|
-
prev !== item
|
|
168
|
-
)
|
|
171
|
+
while ((prev = current[symbol]) && prev[keyProp] >= prop && prev !== item)
|
|
169
172
|
current = prev;
|
|
170
173
|
if (prev === item) {
|
|
171
|
-
|
|
174
|
+
current[symbol] = prev[symbol];
|
|
172
175
|
delete prev[symbol];
|
|
173
176
|
}
|
|
174
177
|
}
|
|
@@ -183,15 +186,15 @@ export class ReverseSortedSet<T extends object> {
|
|
|
183
186
|
*/
|
|
184
187
|
clear(): void {
|
|
185
188
|
const symbol = this.symbols[0];
|
|
186
|
-
let current
|
|
189
|
+
let current = this.tail;
|
|
187
190
|
while (current) {
|
|
188
|
-
const prev = current[symbol]
|
|
191
|
+
const prev = current[symbol];
|
|
189
192
|
for (const symbol of this.symbols) {
|
|
190
193
|
if (!(symbol in current)) break;
|
|
191
194
|
delete current[symbol];
|
|
192
195
|
}
|
|
193
196
|
current = prev;
|
|
194
197
|
}
|
|
195
|
-
this.tail = {}
|
|
198
|
+
this.tail = {};
|
|
196
199
|
}
|
|
197
200
|
}
|