atomic-fns 0.3.0 → 0.3.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.
Files changed (85) hide show
  1. package/.esdoc.json +2 -2
  2. package/README.md +48 -13
  3. package/core/collections/BTree.d.ts +229 -0
  4. package/core/collections/BTree.js +1165 -0
  5. package/core/collections/BTree.ts +1340 -0
  6. package/core/collections/Heap.d.ts +69 -0
  7. package/core/collections/Heap.js +181 -0
  8. package/core/collections/Heap.ts +189 -0
  9. package/core/collections/LRUCache.d.ts +131 -0
  10. package/core/collections/LRUCache.js +388 -0
  11. package/core/collections/LRUCache.ts +465 -0
  12. package/core/collections/SortedMap.d.ts +92 -0
  13. package/core/collections/SortedMap.js +130 -0
  14. package/core/collections/SortedMap.ts +146 -0
  15. package/core/collections/SortedSet.d.ts +63 -0
  16. package/core/collections/SortedSet.js +93 -0
  17. package/core/collections/SortedSet.ts +104 -0
  18. package/core/collections/SortedTree.d.ts +103 -0
  19. package/core/collections/SortedTree.js +141 -0
  20. package/core/collections/SortedTree.ts +160 -0
  21. package/core/collections/SplayTree.d.ts +105 -0
  22. package/core/collections/SplayTree.js +338 -0
  23. package/core/collections/SplayTree.ts +354 -0
  24. package/core/collections/abc.d.ts +152 -0
  25. package/core/collections/abc.js +39 -0
  26. package/core/collections/abc.ts +176 -0
  27. package/core/collections/deque.d.ts +110 -0
  28. package/core/collections/deque.js +285 -0
  29. package/core/collections/deque.ts +329 -0
  30. package/core/collections/frozenset.d.ts +19 -0
  31. package/core/collections/frozenset.js +33 -0
  32. package/core/collections/frozenset.ts +37 -0
  33. package/{src → core}/collections/index.d.ts +12 -161
  34. package/{src → core}/collections/index.js +13 -164
  35. package/{src → core}/collections/index.ts +13 -224
  36. package/core/collections/test.html +10 -0
  37. package/core/collections/typedArrays.d.ts +31 -0
  38. package/core/collections/typedArrays.js +143 -0
  39. package/core/collections/typedArrays.ts +163 -0
  40. package/{src → core}/datetime/index.d.ts +0 -0
  41. package/{src → core}/datetime/index.js +0 -0
  42. package/{src → core}/datetime/index.ts +0 -0
  43. package/core/datetime/test.html +0 -0
  44. package/{src → core}/functools/index.d.ts +2 -2
  45. package/{src → core}/functools/index.js +2 -2
  46. package/{src → core}/functools/index.ts +2 -2
  47. package/{src → core}/globals/index.d.ts +2 -7
  48. package/{src → core}/globals/index.js +5 -2
  49. package/{src → core}/globals/index.ts +6 -9
  50. package/{src → core}/index.d.ts +0 -0
  51. package/{src → core}/index.js +0 -0
  52. package/{src → core}/index.ts +0 -0
  53. package/{src → core}/itertools/index.d.ts +9 -7
  54. package/{src → core}/itertools/index.js +25 -9
  55. package/{src → core}/itertools/index.ts +39 -16
  56. package/{src → core}/math/index.d.ts +0 -0
  57. package/{src → core}/math/index.js +0 -0
  58. package/{src → core}/math/index.ts +0 -0
  59. package/core/operators/index.d.ts +148 -0
  60. package/core/operators/index.js +271 -0
  61. package/core/operators/index.ts +282 -0
  62. package/{src → core}/random/index.d.ts +0 -0
  63. package/{src → core}/random/index.js +0 -0
  64. package/{src → core}/random/index.ts +0 -0
  65. package/package.json +7 -4
  66. package/tests/BTree.spec.ts +143 -0
  67. package/tests/Cache.spec.ts +161 -0
  68. package/tests/Heap.spec.ts +66 -0
  69. package/tests/SortedMap.spec.ts +144 -0
  70. package/tests/SortedSet.spec.ts +84 -0
  71. package/tests/SortedTree.spec.ts +164 -0
  72. package/tests/SplayTree.spec.ts +121 -0
  73. package/tests/collections.spec.ts +1 -1
  74. package/tests/deque.spec.ts +107 -0
  75. package/tests/globals.spec.ts +2 -2
  76. package/tests/itertools.spec.ts +2 -2
  77. package/tests/math.spec.ts +1 -1
  78. package/tests/operators.spec.ts +5 -5
  79. package/tests/random.spec.ts +10 -10
  80. package/tsconfig.json +10 -10
  81. package/tsconfig.node.json +2 -2
  82. package/tsconfig.xo.json +2 -2
  83. package/src/operators/index.d.ts +0 -31
  84. package/src/operators/index.js +0 -171
  85. package/src/operators/index.ts +0 -175
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Returns a new immutable Set object with elements from `iterable`. Its contents cannot be altered after it's created.
3
+ *
4
+ *
5
+ * @class FrozenSet
6
+ * @extends {Set<T>}
7
+ * @template T
8
+ */
9
+ export declare class FrozenSet<T = any> extends Set<T> {
10
+ constructor(iterable: Iterable<T>);
11
+ /** @private */
12
+ add(): this;
13
+ /** @private */
14
+ delete(): boolean;
15
+ /** @private */
16
+ clear(): this;
17
+ /** @private */
18
+ freeze(): Readonly<this>;
19
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Returns a new immutable Set object with elements from `iterable`. Its contents cannot be altered after it's created.
3
+ *
4
+ *
5
+ * @class FrozenSet
6
+ * @extends {Set<T>}
7
+ * @template T
8
+ */
9
+ export class FrozenSet extends Set {
10
+ constructor(iterable) {
11
+ super(iterable);
12
+ return this.freeze();
13
+ }
14
+ /** @private */
15
+ add() {
16
+ throw TypeError('FrozenSet cannot be modified.');
17
+ return this; // eslint-disable-line
18
+ }
19
+ /** @private */
20
+ delete() {
21
+ throw TypeError('FrozenSet cannot be modified.');
22
+ return false; // eslint-disable-line
23
+ }
24
+ /** @private */
25
+ clear() {
26
+ throw TypeError('FrozenSet cannot be modified.');
27
+ return this; // eslint-disable-line
28
+ }
29
+ /** @private */
30
+ freeze() {
31
+ return Object.freeze(this);
32
+ }
33
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Returns a new immutable Set object with elements from `iterable`. Its contents cannot be altered after it's created.
3
+ *
4
+ *
5
+ * @class FrozenSet
6
+ * @extends {Set<T>}
7
+ * @template T
8
+ */
9
+ export class FrozenSet<T = any> extends Set<T> {
10
+ constructor(iterable: Iterable<T>) {
11
+ super(iterable)
12
+ return this.freeze()
13
+ }
14
+
15
+ /** @private */
16
+ add() {
17
+ throw TypeError('FrozenSet cannot be modified.')
18
+ return this // eslint-disable-line
19
+ }
20
+
21
+ /** @private */
22
+ delete() {
23
+ throw TypeError('FrozenSet cannot be modified.')
24
+ return false // eslint-disable-line
25
+ }
26
+
27
+ /** @private */
28
+ clear() {
29
+ throw TypeError('FrozenSet cannot be modified.')
30
+ return this // eslint-disable-line
31
+ }
32
+
33
+ /** @private */
34
+ freeze() {
35
+ return Object.freeze(this)
36
+ }
37
+ }
@@ -4,167 +4,18 @@
4
4
  * @module Collections
5
5
  */
6
6
  import { Iteratee } from '../globals/index.js';
7
- /**
8
- * A container type that provides contains().
9
- *
10
- *
11
- * @interface Container
12
- */
13
- export interface Container {
14
- contains: (x: any) => boolean;
15
- }
16
- /**
17
- * These are the "rich comparison" methods, inspired by Python operators.
18
- *
19
- *
20
- * @interface Comparable
21
- */
22
- export interface Comparable {
23
- /** x < y: calls this.lt(other) reflection. */
24
- lt?: (other: any) => boolean;
25
- /** x ≤ y: calls this.le(other) reflection. */
26
- le?: (other: any) => boolean;
27
- /** x == y: calls this.eq(other) reflection. */
28
- eq: (other: any) => boolean;
29
- /** x != y: calls this.ne(other) reflection. */
30
- ne: (other: any) => boolean;
31
- /** x > y: calls this.gt(other) reflection. */
32
- gt?: (other: any) => boolean;
33
- /** x ≥ y: calls this.ge(other) reflection. */
34
- ge?: (other: any) => boolean;
35
- }
36
- /**
37
- * A `Collection` is an iterable {@link Container} type.
38
- * This is an abstract base class for user-defined collection types.
39
- *
40
- *
41
- * @abstract
42
- * @class Collection
43
- * @implements {Container}
44
- */
45
- export declare abstract class Collection implements Container {
46
- /**
47
- * Returns an iterator for the container items
48
- * @return {Iterator}
49
- */
50
- [Symbol.iterator](): this;
51
- /**
52
- * Implements the iterator protocol and returns the next item in the iterable.
53
- */
54
- next(): void;
55
- /**
56
- * Adds a new item to the container.
57
- * @param item - The item to add to the collection.
58
- */
59
- add(item: any): void;
60
- /**
61
- * Checks if item is present in the container.
62
- * @param item - The item to search for in the collection.
63
- * @returns `true` when the element is found, else `false`
64
- */
65
- contains(item: any): boolean;
66
- /**
67
- * Returns the total number of elements in the container.
68
- */
69
- size(): number;
70
- /**
71
- * Remove the first item from the container where `item == x`
72
- * @returns `true` when the element is found and removed, else `false`
73
- */
74
- remove(x: any): boolean;
75
- /**
76
- * Retrieve and remove the item at index `i`.
77
- * @returns the item or undefined if not found.
78
- */
79
- pop(i: any): void;
80
- /**
81
- * Remove all items from the container
82
- */
83
- clear(): void;
84
- }
85
- /**
86
- * Implements an iterable that allows backward iteration.
87
- * @interface Reversible
88
- */
89
- export interface Reversible<T = unknown> {
90
- reversed: () => Iterator<T>;
91
- }
92
- /**
93
- * A sequence is an iterable {@link Collection} type with efficient index-based access.
94
- * @abstract
95
- * @class Sequence
96
- * @extends {Collection}
97
- * @template T
98
- */
99
- export declare abstract class Sequence<T> extends Collection implements Reversible<T> {
100
- /**
101
- * Return the item at the given key or index
102
- * @param {*} key
103
- * @memberof Sequence
104
- */
105
- get(key: any): T | undefined;
106
- /**
107
- * Set a new value at the given key or index
108
- *
109
- * @param {*} key
110
- * @param {T} val
111
- * @memberof Sequence
112
- */
113
- set(key: any, val: T): void;
114
- /**
115
- * Deletes the given key or index, and its value.
116
- * Raises ValueError if not key is found.
117
- *
118
- * @param {*} key
119
- * @memberof Sequence
120
- */
121
- delete(key: any): void;
122
- /**
123
- * Adds a new item to the end of the sequence.
124
- *
125
- * @param {T} x
126
- * @memberof Sequence
127
- */
128
- append(x: T): void;
129
- /**
130
- * Append all the items to the sequence.
131
- *
132
- * @param {Iterable<T>} iter
133
- * @memberof Sequence
134
- */
135
- extend(iter: Iterable<T>): void;
136
- /**
137
- * Return the index of x in the sequence, or undefined if not found.
138
- *
139
- * @param {T} item
140
- * @return {(number | undefined)}
141
- * @memberof Sequence
142
- */
143
- indexOf(item: T): number | undefined;
144
- size(): number;
145
- reversed(): Iterator<T>;
146
- }
147
- /**
148
- * Returns a new immutable Set object with elements from `iterable`. Its contents cannot be altered after it's created.
149
- *
150
- *
151
- * @class FrozenSet
152
- * @extends {Set<T>}
153
- * @template T
154
- */
155
- export declare class FrozenSet<T = any> extends Set<T> {
156
- constructor(iterable: Iterable<T>);
157
- /** @private */
158
- add(): this;
159
- /** @private */
160
- delete(): boolean;
161
- /** @private */
162
- clear(): this;
163
- /** @private */
164
- freeze(): Readonly<this>;
165
- }
166
- /**
167
- * Creates a new array with all `falsey` and empty values removed.
7
+ export * from './abc.js';
8
+ export * from './BTree.js';
9
+ export * from './deque.js';
10
+ export * from './frozenset.js';
11
+ export * from './Heap.js';
12
+ export * from './LRUCache.js';
13
+ export * from './SortedSet.js';
14
+ export * from './SortedMap.js';
15
+ export * from './SortedTree.js';
16
+ export * from './SplayTree.js';
17
+ /**
18
+ * Creates a new array with all falsy and empty values removed.
168
19
  * @param arr The array to compact
169
20
  * @returns A new array with the filtered values.
170
21
  * @example
@@ -4,166 +4,19 @@
4
4
  * @module Collections
5
5
  */
6
6
  import { partial } from '../functools/index.js';
7
- import { call, get, isArray, isArrayLike, isBool, isEmpty, isFunc, isIterable, isNull, isNumber, isObject, isString, isSymbol, keys, NotImplementedError, set } from '../globals/index.js';
7
+ import { call, get, isArray, isArrayLike, isBool, isEmpty, isFunc, isIterable, isNull, isNumber, isObject, isString, isSymbol, keys, set } from '../globals/index.js';
8
8
  import { enumerate } from '../itertools/index.js';
9
- import { comp, eq, id } from '../operators/index.js';
10
- /**
11
- * A `Collection` is an iterable {@link Container} type.
12
- * This is an abstract base class for user-defined collection types.
13
- *
14
- *
15
- * @abstract
16
- * @class Collection
17
- * @implements {Container}
18
- */
19
- export class Collection {
20
- /**
21
- * Returns an iterator for the container items
22
- * @return {Iterator}
23
- */
24
- [Symbol.iterator]() {
25
- return this;
26
- }
27
- /**
28
- * Implements the iterator protocol and returns the next item in the iterable.
29
- */
30
- next() { }
31
- /**
32
- * Adds a new item to the container.
33
- * @param item - The item to add to the collection.
34
- */
35
- add(item) { }
36
- /**
37
- * Checks if item is present in the container.
38
- * @param item - The item to search for in the collection.
39
- * @returns `true` when the element is found, else `false`
40
- */
41
- contains(item) {
42
- return false;
43
- }
44
- /**
45
- * Returns the total number of elements in the container.
46
- */
47
- size() {
48
- throw new NotImplementedError();
49
- }
50
- /**
51
- * Remove the first item from the container where `item == x`
52
- * @returns `true` when the element is found and removed, else `false`
53
- */
54
- remove(x) {
55
- return false;
56
- }
57
- /**
58
- * Retrieve and remove the item at index `i`.
59
- * @returns the item or undefined if not found.
60
- */
61
- pop(i) { }
62
- /**
63
- * Remove all items from the container
64
- */
65
- clear() { }
66
- }
67
- /**
68
- * A sequence is an iterable {@link Collection} type with efficient index-based access.
69
- * @abstract
70
- * @class Sequence
71
- * @extends {Collection}
72
- * @template T
73
- */
74
- export class Sequence extends Collection {
75
- /**
76
- * Return the item at the given key or index
77
- * @param {*} key
78
- * @memberof Sequence
79
- */
80
- get(key) {
81
- throw new NotImplementedError();
82
- }
83
- /**
84
- * Set a new value at the given key or index
85
- *
86
- * @param {*} key
87
- * @param {T} val
88
- * @memberof Sequence
89
- */
90
- set(key, val) {
91
- throw new NotImplementedError();
92
- }
93
- /**
94
- * Deletes the given key or index, and its value.
95
- * Raises ValueError if not key is found.
96
- *
97
- * @param {*} key
98
- * @memberof Sequence
99
- */
100
- delete(key) {
101
- throw new NotImplementedError();
102
- }
103
- /**
104
- * Adds a new item to the end of the sequence.
105
- *
106
- * @param {T} x
107
- * @memberof Sequence
108
- */
109
- append(x) { }
110
- /**
111
- * Append all the items to the sequence.
112
- *
113
- * @param {Iterable<T>} iter
114
- * @memberof Sequence
115
- */
116
- extend(iter) { }
117
- /**
118
- * Return the index of x in the sequence, or undefined if not found.
119
- *
120
- * @param {T} item
121
- * @return {(number | undefined)}
122
- * @memberof Sequence
123
- */
124
- indexOf(item) {
125
- throw new NotImplementedError();
126
- }
127
- size() {
128
- return 0;
129
- }
130
- reversed() {
131
- throw new NotImplementedError();
132
- }
133
- }
134
- /**
135
- * Returns a new immutable Set object with elements from `iterable`. Its contents cannot be altered after it's created.
136
- *
137
- *
138
- * @class FrozenSet
139
- * @extends {Set<T>}
140
- * @template T
141
- */
142
- export class FrozenSet extends Set {
143
- constructor(iterable) {
144
- super(iterable);
145
- return this.freeze();
146
- }
147
- /** @private */
148
- add() {
149
- throw TypeError('FrozenSet cannot be modified.');
150
- return this; // eslint-disable-line
151
- }
152
- /** @private */
153
- delete() {
154
- throw TypeError('FrozenSet cannot be modified.');
155
- return false; // eslint-disable-line
156
- }
157
- /** @private */
158
- clear() {
159
- throw TypeError('FrozenSet cannot be modified.');
160
- return this; // eslint-disable-line
161
- }
162
- /** @private */
163
- freeze() {
164
- return Object.freeze(this);
165
- }
166
- }
9
+ import { compare, eq, id } from '../operators/index.js';
10
+ export * from './abc.js';
11
+ export * from './BTree.js';
12
+ export * from './deque.js';
13
+ export * from './frozenset.js';
14
+ export * from './Heap.js';
15
+ export * from './LRUCache.js';
16
+ export * from './SortedSet.js';
17
+ export * from './SortedMap.js';
18
+ export * from './SortedTree.js';
19
+ export * from './SplayTree.js';
167
20
  export function compact(arr) {
168
21
  if (arr == null)
169
22
  return;
@@ -852,7 +705,7 @@ uniq([2, 1, 2])
852
705
  */
853
706
  export function sortedUniq(arr, fn = id) {
854
707
  const values = uniq(arr, fn);
855
- values.sort(comp);
708
+ values.sort(compare);
856
709
  return values;
857
710
  }
858
711
  function baseMergeDeep(obj, source, key, stack) {
@@ -1084,8 +937,4 @@ export function remove(arr, func) {
1084
937
  });
1085
938
  }
1086
939
  // TODO: binary search utils
1087
- // TODO: heap/heapify
1088
- // TODO: deque
1089
940
  // TODO: Counter
1090
- // TODO: Skip list
1091
- // TODO: BST (BTree)