splaytree 3.1.0 → 3.1.2
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 +58 -57
- package/dist/splay.esm.js +75 -1
- package/dist/splay.esm.js.map +1 -1
- package/dist/splay.js +678 -604
- package/dist/splay.js.map +1 -1
- package/package.json +5 -3
- package/src/index.ts +22 -2
- package/typings/index.d.ts +3 -2
- package/dist/index.d.ts +0 -81
- package/dist/index.js +0 -572
- package/dist/node.d.ts +0 -8
- package/dist/node.js +0 -9
- package/dist/types.d.ts +0 -2
- package/dist/types.js +0 -0
package/dist/splay.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"splay.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"splay.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "splaytree",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.2",
|
|
4
4
|
"author": "Alexander Milevski <info@w8r.name>",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Fast Splay tree for Node and browser",
|
|
@@ -33,7 +33,8 @@
|
|
|
33
33
|
"test": "nyc mocha tests/**/*.test.ts",
|
|
34
34
|
"posttest": "nyc report --reporter=json",
|
|
35
35
|
"prepublishOnly": "npm run build && npm test",
|
|
36
|
-
"clean": "rm -rf dist coverage .nyc"
|
|
36
|
+
"clean": "rm -rf dist coverage .nyc",
|
|
37
|
+
"coverage": "codecov -f coverage/*.json"
|
|
37
38
|
},
|
|
38
39
|
"devDependencies": {
|
|
39
40
|
"@types/chai": "^4.1.4",
|
|
@@ -42,8 +43,9 @@
|
|
|
42
43
|
"benchmark": "^2.1.4",
|
|
43
44
|
"bintrees": "^1.0.2",
|
|
44
45
|
"chai": "^4.2.0",
|
|
46
|
+
"codecov": "^3.8.3",
|
|
45
47
|
"mocha": "^6.2.0",
|
|
46
|
-
"nodemon": "^
|
|
48
|
+
"nodemon": "^2.0.20",
|
|
47
49
|
"nyc": "^14.1.1",
|
|
48
50
|
"reify": "*",
|
|
49
51
|
"rollup": "*",
|
package/src/index.ts
CHANGED
|
@@ -381,13 +381,13 @@ export default class Tree<Key=number, Value=any> {
|
|
|
381
381
|
}
|
|
382
382
|
|
|
383
383
|
|
|
384
|
-
public minNode(t = this._root) : Node<Key, Value> {
|
|
384
|
+
public minNode(t = this._root) : Node<Key, Value> | null {
|
|
385
385
|
if (t) while (t.left) t = t.left;
|
|
386
386
|
return t;
|
|
387
387
|
}
|
|
388
388
|
|
|
389
389
|
|
|
390
|
-
public maxNode(t = this._root) : Node<Key, Value> {
|
|
390
|
+
public maxNode(t = this._root) : Node<Key, Value> | null {
|
|
391
391
|
if (t) while (t.right) t = t.right;
|
|
392
392
|
return t;
|
|
393
393
|
}
|
|
@@ -529,6 +529,26 @@ export default class Tree<Key=number, Value=any> {
|
|
|
529
529
|
public split(key:Key) {
|
|
530
530
|
return split(key, this._root, this._comparator);
|
|
531
531
|
}
|
|
532
|
+
|
|
533
|
+
*[Symbol.iterator]() {
|
|
534
|
+
let current = this._root;
|
|
535
|
+
const Q: Node<Key, Value>[] = []; /* Initialize stack s */
|
|
536
|
+
let done = false;
|
|
537
|
+
|
|
538
|
+
while (!done) {
|
|
539
|
+
if (current !== null) {
|
|
540
|
+
Q.push(current);
|
|
541
|
+
current = current.left;
|
|
542
|
+
} else {
|
|
543
|
+
if (Q.length !== 0) {
|
|
544
|
+
current = Q.pop()!;
|
|
545
|
+
yield current;
|
|
546
|
+
|
|
547
|
+
current = current.right;
|
|
548
|
+
} else done = true;
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
}
|
|
532
552
|
}
|
|
533
553
|
|
|
534
554
|
|
package/typings/index.d.ts
CHANGED
|
@@ -54,8 +54,8 @@ export default class Tree<Key = number, Value = any> {
|
|
|
54
54
|
values(): Value[];
|
|
55
55
|
min(): Key | null;
|
|
56
56
|
max(): Key | null;
|
|
57
|
-
minNode(t?: Node<Key, Value>): Node<Key, Value
|
|
58
|
-
maxNode(t?: Node<Key, Value>): Node<Key, Value
|
|
57
|
+
minNode(t?: Node<Key, Value>): Node<Key, Value> | null;
|
|
58
|
+
maxNode(t?: Node<Key, Value>): Node<Key, Value> | null;
|
|
59
59
|
/**
|
|
60
60
|
* Returns node at given index
|
|
61
61
|
*/
|
|
@@ -77,5 +77,6 @@ export default class Tree<Key = number, Value = any> {
|
|
|
77
77
|
left: Node<any, any>;
|
|
78
78
|
right: Node<any, any>;
|
|
79
79
|
};
|
|
80
|
+
[Symbol.iterator](): IterableIterator<Node<Key, Value>>;
|
|
80
81
|
}
|
|
81
82
|
export {};
|
package/dist/index.d.ts
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import Node from './node';
|
|
2
|
-
import { Key } from './types';
|
|
3
|
-
export declare type Comparator<Key> = (a: Key, b: Key) => number;
|
|
4
|
-
export declare type Visitor<Key, Value> = (node: Node<Key, Value>) => void;
|
|
5
|
-
export declare type NodePrinter<Key, Value> = (node: Node<Key, Value>) => string;
|
|
6
|
-
declare function DEFAULT_COMPARE(a: Key, b: Key): number;
|
|
7
|
-
export default class Tree<Key = number, Value = any> {
|
|
8
|
-
private _comparator;
|
|
9
|
-
private _root;
|
|
10
|
-
private _size;
|
|
11
|
-
constructor(comparator?: typeof DEFAULT_COMPARE);
|
|
12
|
-
/**
|
|
13
|
-
* Inserts a key, allows duplicates
|
|
14
|
-
*/
|
|
15
|
-
insert(key: Key, data?: Value): Node<Key, Value>;
|
|
16
|
-
/**
|
|
17
|
-
* Adds a key, if it is not present in the tree
|
|
18
|
-
*/
|
|
19
|
-
add(key: Key, data?: Value): Node<Key, Value>;
|
|
20
|
-
/**
|
|
21
|
-
* @param {Key} key
|
|
22
|
-
* @return {Node|null}
|
|
23
|
-
*/
|
|
24
|
-
remove(key: Key): void;
|
|
25
|
-
/**
|
|
26
|
-
* Deletes i from the tree if it's there
|
|
27
|
-
*/
|
|
28
|
-
_remove(i: Key, t: Node<Key, Value>, comparator: Comparator<Key>): Node<Key, Value>;
|
|
29
|
-
/**
|
|
30
|
-
* Removes and returns the node with smallest key
|
|
31
|
-
*/
|
|
32
|
-
pop(): {
|
|
33
|
-
key: Key;
|
|
34
|
-
data: Value;
|
|
35
|
-
} | null;
|
|
36
|
-
/**
|
|
37
|
-
* Find without splaying
|
|
38
|
-
*/
|
|
39
|
-
findStatic(key: Key): Node<Key, Value> | null;
|
|
40
|
-
find(key: Key): Node<Key, Value> | null;
|
|
41
|
-
contains(key: Key): boolean;
|
|
42
|
-
forEach(visitor: Visitor<Key, Value>, ctx?: any): Tree<Key, Value>;
|
|
43
|
-
/**
|
|
44
|
-
* Walk key range from `low` to `high`. Stops if `fn` returns a value.
|
|
45
|
-
*/
|
|
46
|
-
range(low: Key, high: Key, fn: Visitor<Key, Value>, ctx?: any): Tree<Key, Value>;
|
|
47
|
-
/**
|
|
48
|
-
* Returns array of keys
|
|
49
|
-
*/
|
|
50
|
-
keys(): Key[];
|
|
51
|
-
/**
|
|
52
|
-
* Returns array of all the data in the nodes
|
|
53
|
-
*/
|
|
54
|
-
values(): Value[];
|
|
55
|
-
min(): Key | null;
|
|
56
|
-
max(): Key | null;
|
|
57
|
-
minNode(t?: Node<Key, Value>): Node<Key, Value>;
|
|
58
|
-
maxNode(t?: Node<Key, Value>): Node<Key, Value>;
|
|
59
|
-
/**
|
|
60
|
-
* Returns node at given index
|
|
61
|
-
*/
|
|
62
|
-
at(index: number): Node<Key, Value> | null;
|
|
63
|
-
next(d: Node<Key, Value>): Node<Key, Value> | null;
|
|
64
|
-
prev(d: Node<Key, Value>): Node<Key, Value> | null;
|
|
65
|
-
clear(): Tree<Key, Value>;
|
|
66
|
-
toList(): Node<any, any>;
|
|
67
|
-
/**
|
|
68
|
-
* Bulk-load items. Both array have to be same size
|
|
69
|
-
*/
|
|
70
|
-
load(keys?: Key[], values?: Value[], presort?: boolean): this;
|
|
71
|
-
isEmpty(): boolean;
|
|
72
|
-
readonly size: number;
|
|
73
|
-
readonly root: Node<Key, Value> | null;
|
|
74
|
-
toString(printNode?: NodePrinter<Key, Value>): string;
|
|
75
|
-
update(key: Key, newKey: Key, newData?: Value): void;
|
|
76
|
-
split(key: Key): {
|
|
77
|
-
left: any;
|
|
78
|
-
right: any;
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
export {};
|