splaytree 3.2.1 → 3.2.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 CHANGED
@@ -41,7 +41,7 @@ Or get it from CDN
41
41
  </script>
42
42
  ```
43
43
 
44
- Or use the compiled version 'dist/splaytree.umd.js'.
44
+ Or use the compiled version 'dist/splaytree.umd.cjs'.
45
45
 
46
46
  [Try it in your browser](https://npm.runkit.com/splaytree)
47
47
 
@@ -0,0 +1,82 @@
1
+ import Node from "./node";
2
+ import { Key } from "./types";
3
+ export type Comparator<Key> = (a: Key, b: Key) => number;
4
+ export type Visitor<Key, Value> = (node: Node<Key, Value>) => undefined | boolean | void;
5
+ export 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
+ private _remove;
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> | null): Node<Key, Value> | null;
58
+ maxNode(t?: Node<Key, Value> | null): Node<Key, Value> | null;
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
+ get size(): number;
73
+ get 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: Node<import("./types").Key, import("./types").Value> | null;
78
+ right: Node<import("./types").Key, import("./types").Value> | null;
79
+ };
80
+ [Symbol.iterator](): Generator<Node<Key, Value>, void, unknown>;
81
+ }
82
+ export {};
@@ -0,0 +1,8 @@
1
+ export default class Node<Key, Value> {
2
+ key: Key;
3
+ data: any;
4
+ left: Node<Key, Value> | null;
5
+ right: Node<Key, Value> | null;
6
+ next: Node<Key, Value> | null;
7
+ constructor(key: Key, data?: any);
8
+ }
@@ -0,0 +1,2 @@
1
+ export type Key = number | any;
2
+ export type Value = any;
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "splaytree",
3
- "version": "3.2.1",
3
+ "version": "3.2.2",
4
4
  "author": "Alexander Milevski <info@w8r.name>",
5
5
  "license": "MIT",
6
6
  "description": "Fast Splay tree for Node and browser",
7
7
  "type": "module",
8
- "main": "dist/splaytree.umd.js",
9
- "browser": "dist/splaytree.umd.js",
10
- "unpkg": "dist/splaytree.umd.js",
8
+ "main": "dist/splaytree.umd.cjs",
9
+ "browser": "dist/splaytree.umd.cjs",
10
+ "unpkg": "dist/splaytree.umd.cjs",
11
11
  "module": "dist/splaytree.mjs",
12
12
  "types": "dist/types/index.d.ts",
13
13
  "files": [
@@ -22,7 +22,7 @@
22
22
  "url": "https://github.com/w8r/splay-tree.git"
23
23
  },
24
24
  "scripts": {
25
- "build": "vite build",
25
+ "build": "vite build && npm run types",
26
26
  "types": "tsc --declaration --emitDeclarationOnly -p tsconfig.build.json",
27
27
  "test": "vitest",
28
28
  "test:watch": "vitest watch",
@@ -53,7 +53,7 @@
53
53
  ".": {
54
54
  "types": "./dist/types/index.d.ts",
55
55
  "import": "./dist/splaytree.mjs",
56
- "require": "./dist/splaytree.umd.js"
56
+ "require": "./dist/splaytree.umd.cjs"
57
57
  }
58
58
  },
59
59
  "engines": {