atomic-fns 0.3.5 → 0.4.3
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 -12
- package/{core → dist}/collections/BTree.d.ts +6 -6
- package/{core → dist}/collections/BTree.js +17 -17
- package/{core → dist}/collections/Heap.d.ts +3 -3
- package/{core → dist}/collections/Heap.js +0 -0
- package/dist/collections/LRUCache.d.ts +80 -0
- package/dist/collections/LRUCache.js +126 -0
- package/{core → dist}/collections/SortedMap.d.ts +2 -2
- package/{core → dist}/collections/SortedMap.js +0 -0
- package/{core → dist}/collections/SortedSet.d.ts +3 -3
- package/{core → dist}/collections/SortedSet.js +1 -1
- package/{core → dist}/collections/SortedTree.d.ts +3 -3
- package/{core → dist}/collections/SortedTree.js +1 -1
- package/{core → dist}/collections/SplayTree.d.ts +5 -5
- package/{core → dist}/collections/SplayTree.js +0 -0
- package/{core → dist}/collections/abc.d.ts +0 -0
- package/{core → dist}/collections/abc.js +0 -0
- package/{core → dist}/collections/deque.d.ts +7 -7
- package/{core → dist}/collections/deque.js +6 -8
- package/{core → dist}/collections/frozenset.d.ts +0 -0
- package/{core → dist}/collections/frozenset.js +3 -6
- package/{core → dist}/collections/index.d.ts +207 -105
- package/{core → dist}/collections/index.js +179 -436
- package/{core → dist}/functools/index.d.ts +30 -16
- package/{core → dist}/functools/index.js +34 -12
- package/dist/globals/decimal.d.ts +142 -0
- package/dist/globals/decimal.js +371 -0
- package/{core → dist}/globals/index.d.ts +26 -25
- package/{core → dist}/globals/index.js +16 -37
- package/dist/i18n/currency.d.ts +24 -0
- package/dist/i18n/currency.js +85 -0
- package/dist/i18n/date/index.d.ts +204 -0
- package/dist/i18n/date/index.js +530 -0
- package/dist/i18n/date/utils.d.ts +65 -0
- package/dist/i18n/date/utils.js +290 -0
- package/dist/i18n/duration.d.ts +112 -0
- package/dist/i18n/duration.js +392 -0
- package/dist/i18n/format.d.ts +26 -0
- package/dist/i18n/format.js +495 -0
- package/{core → dist}/i18n/index.d.ts +2 -1
- package/{core → dist}/i18n/index.js +2 -1
- package/{core → dist}/index.d.ts +0 -0
- package/{core → dist}/index.js +0 -0
- package/{core → dist}/itertools/index.d.ts +74 -46
- package/{core → dist}/itertools/index.js +28 -56
- package/{core → dist}/math/index.d.ts +9 -10
- package/{core → dist}/math/index.js +3 -1
- package/{core → dist}/operators/index.d.ts +4 -4
- package/{core → dist}/operators/index.js +2 -8
- package/{core → dist}/random/index.d.ts +1 -1
- package/{core → dist}/random/index.js +5 -5
- package/package.json +28 -42
- package/.editorconfig +0 -12
- package/.esdoc.json +0 -27
- package/.eslintignore +0 -1
- package/.eslintrc.json +0 -35
- package/.firebaserc +0 -5
- package/.prettierrc +0 -19
- package/core/collections/BTree.ts +0 -1340
- package/core/collections/Heap.ts +0 -189
- package/core/collections/LRUCache.d.ts +0 -152
- package/core/collections/LRUCache.js +0 -409
- package/core/collections/LRUCache.ts +0 -486
- package/core/collections/SortedMap.ts +0 -146
- package/core/collections/SortedSet.ts +0 -110
- package/core/collections/SortedTree.ts +0 -160
- package/core/collections/SplayTree.ts +0 -354
- package/core/collections/abc.ts +0 -176
- package/core/collections/deque.ts +0 -338
- package/core/collections/frozenset.ts +0 -37
- package/core/collections/index.ts +0 -1024
- package/core/collections/test.html +0 -10
- package/core/collections/typedArrays.d.ts +0 -31
- package/core/collections/typedArrays.js +0 -143
- package/core/collections/typedArrays.ts +0 -163
- package/core/functools/index.ts +0 -260
- package/core/globals/index.ts +0 -481
- package/core/i18n/date/format.d.ts +0 -16
- package/core/i18n/date/format.js +0 -307
- package/core/i18n/date/format.ts +0 -343
- package/core/i18n/date/index.d.ts +0 -224
- package/core/i18n/date/index.js +0 -387
- package/core/i18n/date/index.ts +0 -471
- package/core/i18n/date/test.html +0 -67
- package/core/i18n/index.ts +0 -8
- package/core/index.ts +0 -8
- package/core/itertools/index.ts +0 -494
- package/core/math/index.ts +0 -152
- package/core/operators/index.ts +0 -310
- package/core/random/index.ts +0 -66
- package/firebase.json +0 -10
- package/jasmine.json +0 -14
- package/tests/BTree.spec.ts +0 -143
- package/tests/Cache.spec.ts +0 -161
- package/tests/Heap.spec.ts +0 -66
- package/tests/SortedMap.spec.ts +0 -144
- package/tests/SortedSet.spec.ts +0 -84
- package/tests/SortedTree.spec.ts +0 -164
- package/tests/SplayTree.spec.ts +0 -121
- package/tests/collections.spec.ts +0 -288
- package/tests/deque.spec.ts +0 -107
- package/tests/globals.spec.ts +0 -270
- package/tests/itertools.spec.ts +0 -266
- package/tests/math.spec.ts +0 -25
- package/tests/operators.spec.ts +0 -40
- package/tests/random.spec.ts +0 -46
- package/tsconfig.json +0 -126
- package/tsconfig.node.json +0 -18
- package/tsconfig.xo.json +0 -9
package/core/collections/abc.ts
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A container type that provides contains().
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* @interface Container
|
|
6
|
-
*/
|
|
7
|
-
export interface Container {
|
|
8
|
-
contains: (x) => boolean
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Implements an equality check between two values.
|
|
13
|
-
* @interface Ordered
|
|
14
|
-
*/
|
|
15
|
-
export interface Equals {
|
|
16
|
-
eq: (other) => boolean
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Implements an iterable that allows comparing two elements to determine ordering.
|
|
21
|
-
* @interface Ordered
|
|
22
|
-
*/
|
|
23
|
-
export interface Comparable {
|
|
24
|
-
compare: (other) => number
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Implements an iterable that allows sorting elements.
|
|
29
|
-
* @interface Ordered
|
|
30
|
-
*/
|
|
31
|
-
export interface Ordered<T> {
|
|
32
|
-
lt: (other) => boolean
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Implements an iterable that allows backward iteration.
|
|
37
|
-
* @interface Reversible
|
|
38
|
-
*/
|
|
39
|
-
export interface Reversible<T = any> {
|
|
40
|
-
reversed: () => Iterable<T>
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* A `Collection` is an iterable {@link Container} type.
|
|
45
|
-
* This is an abstract base class for user-defined collection types.
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* @abstract
|
|
49
|
-
* @class Collection
|
|
50
|
-
* @implements {Container}
|
|
51
|
-
*/
|
|
52
|
-
export abstract class Collection implements Container {
|
|
53
|
-
/**
|
|
54
|
-
* Adds a new item to the collection.
|
|
55
|
-
* @param item - The item to add to the collection.
|
|
56
|
-
*/
|
|
57
|
-
abstract add(item): any
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Checks if item is present in the collection.
|
|
61
|
-
* @param item - The item to search for in the collection.
|
|
62
|
-
* @returns `true` when the element is found, else `false`
|
|
63
|
-
*/
|
|
64
|
-
abstract contains(item): boolean
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Remove all items from the collection
|
|
68
|
-
*/
|
|
69
|
-
abstract clear()
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Returns the total number of elements in the collection.
|
|
73
|
-
*/
|
|
74
|
-
abstract get size(): number
|
|
75
|
-
|
|
76
|
-
get length() {
|
|
77
|
-
return this.size
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Check if there are no items.
|
|
82
|
-
* @returns {boolean} `true` if is empty.
|
|
83
|
-
*/
|
|
84
|
-
empty() {
|
|
85
|
-
return !this.size
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* A sequence is an iterable {@link Collection} type with efficient index-based access.
|
|
91
|
-
* @abstract
|
|
92
|
-
* @class Sequence
|
|
93
|
-
* @extends {Collection}
|
|
94
|
-
* @template V
|
|
95
|
-
*/
|
|
96
|
-
export abstract class Sequence<V = any, K = any> extends Collection {
|
|
97
|
-
/**
|
|
98
|
-
* Return the item at the given key or index
|
|
99
|
-
* @param {K} key
|
|
100
|
-
* @memberof Sequence
|
|
101
|
-
*/
|
|
102
|
-
abstract get(key: K)
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Set a new value at the given key or index
|
|
106
|
-
*
|
|
107
|
-
* @param {K} key
|
|
108
|
-
* @param {V} value
|
|
109
|
-
* @memberof Sequence
|
|
110
|
-
*/
|
|
111
|
-
abstract set(key: K, value: V)
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Adds a new item to the end of the sequence. Alias of {@link Collection.add}.
|
|
115
|
-
*
|
|
116
|
-
* @param {V} x
|
|
117
|
-
* @memberof Sequence
|
|
118
|
-
*/
|
|
119
|
-
abstract append(x: V | Iterable<V>)
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Remove a given value from the collection if exists.
|
|
123
|
-
* @returns the value that was removed or `undefined`.
|
|
124
|
-
*/
|
|
125
|
-
abstract remove(x: V)
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Returns an iterator of all the `keys` in order.
|
|
129
|
-
*/
|
|
130
|
-
abstract keys(): Iterable<K>
|
|
131
|
-
/**
|
|
132
|
-
* Returns an iterator of all the `values` in order.
|
|
133
|
-
*/
|
|
134
|
-
abstract values(): Iterable<V>
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Returns an iterator of all the `[key, value]` pairs in order.
|
|
138
|
-
*/
|
|
139
|
-
abstract entries(): Iterable<[K, V]>
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* A mapping is a {@link Collection} indexed by keys that may have associated values.
|
|
144
|
-
* @abstract
|
|
145
|
-
* @class Mapping
|
|
146
|
-
* @extends {Collection}
|
|
147
|
-
* @template K, V
|
|
148
|
-
*/
|
|
149
|
-
export abstract class Mapping<K, V> extends Collection {
|
|
150
|
-
/**
|
|
151
|
-
* Returns the value for the given key, or return `defaults` if not found.
|
|
152
|
-
* @param {K} key
|
|
153
|
-
* @param {*} [defaults]
|
|
154
|
-
*/
|
|
155
|
-
abstract get(key: K, defaults?): V | undefined
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Sets the value for the given key.
|
|
159
|
-
* @param {K} key
|
|
160
|
-
*/
|
|
161
|
-
abstract set(key: K, value: V)
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Returns an iterator of all the `keys` in the map.
|
|
165
|
-
*/
|
|
166
|
-
abstract keys(): Iterable<K>
|
|
167
|
-
/**
|
|
168
|
-
* Returns an iterator of all the `values` in the map.
|
|
169
|
-
*/
|
|
170
|
-
abstract values(): Iterable<V>
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Returns an iterator of all the `[key, value]` pairs in the map.
|
|
174
|
-
*/
|
|
175
|
-
abstract entries(): Iterable<[K, V]>
|
|
176
|
-
}
|
|
@@ -1,338 +0,0 @@
|
|
|
1
|
-
import { Iteratee, KeyError, ValueError } from '../globals/index.js'
|
|
2
|
-
import { IterableIterator } from '../itertools/index.js'
|
|
3
|
-
import { eq } from '../operators/index.js'
|
|
4
|
-
import { Sequence } from './abc.js'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Fixed capacity double-ended queue implemented as ring deque.
|
|
8
|
-
* @template T
|
|
9
|
-
*/
|
|
10
|
-
export class Deque<T = any> extends Sequence<T> {
|
|
11
|
-
items: T[]
|
|
12
|
-
start: number = 0
|
|
13
|
-
count: number = 0
|
|
14
|
-
capacity: number
|
|
15
|
-
ArrayConstructor: any
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Creates a new `Deque` instance of a fixed size.
|
|
19
|
-
* @param {Array} [arrType = []] The initial elements or array type to use (accepts any kind of typed array).
|
|
20
|
-
* @param {number} [capacity=1024] The fixed size of the deque. Defaults to `1024`.
|
|
21
|
-
*/
|
|
22
|
-
constructor(arrType = [] as T[], capacity = 1024) {
|
|
23
|
-
super()
|
|
24
|
-
if (typeof capacity !== 'number' || capacity <= 0)
|
|
25
|
-
throw new ValueError(`Deque capacity should be a positive integer.`)
|
|
26
|
-
|
|
27
|
-
this.ArrayConstructor = arrType.constructor
|
|
28
|
-
this.capacity = capacity
|
|
29
|
-
this.items = new this.ArrayConstructor(arrType.length || this.capacity)
|
|
30
|
-
this.clear()
|
|
31
|
-
|
|
32
|
-
if (arrType.length) {
|
|
33
|
-
for (const item of arrType) {
|
|
34
|
-
this.append(item)
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/** Returns the total number of elements in the deque. */
|
|
40
|
-
get size() {
|
|
41
|
-
return this.count
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Method used to clear the structure.
|
|
46
|
-
*/
|
|
47
|
-
clear() {
|
|
48
|
-
// Properties
|
|
49
|
-
this.start = 0
|
|
50
|
-
this.count = 0
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Alias of {@link Deque.append}
|
|
55
|
-
* @param {T} item Item to append.
|
|
56
|
-
* @returns {number} Returns the new size of the deque.
|
|
57
|
-
*/
|
|
58
|
-
add(item) {
|
|
59
|
-
return this.append(item)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Appends a new element to the end of the deque.
|
|
64
|
-
* @param {T} item Item to append.
|
|
65
|
-
* @returns {number} Returns the new size of the deque.
|
|
66
|
-
*/
|
|
67
|
-
append(item) {
|
|
68
|
-
if (this.count === this.capacity) this.popleft()
|
|
69
|
-
|
|
70
|
-
const index = (this.start + this.count) % this.capacity
|
|
71
|
-
|
|
72
|
-
this.items[index] = item
|
|
73
|
-
|
|
74
|
-
return ++this.count
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Appends a new element to the beginning of the deque.
|
|
79
|
-
* @param {T} item Item to prepend.
|
|
80
|
-
* @returns {number} Returns the new size of the deque.
|
|
81
|
-
*/
|
|
82
|
-
appendleft(item) {
|
|
83
|
-
if (this.count === this.capacity) this.pop()
|
|
84
|
-
|
|
85
|
-
let index = this.start - 1
|
|
86
|
-
|
|
87
|
-
if (this.start === 0) index = this.capacity - 1
|
|
88
|
-
|
|
89
|
-
this.items[index] = item
|
|
90
|
-
this.start = index
|
|
91
|
-
|
|
92
|
-
return ++this.count
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Removes and returns the element at the end of the deque.
|
|
97
|
-
* @returns {?T} Returns the popped item.
|
|
98
|
-
*/
|
|
99
|
-
pop() {
|
|
100
|
-
if (this.count === 0) return
|
|
101
|
-
|
|
102
|
-
const index = (this.start + this.count - 1) % this.capacity
|
|
103
|
-
|
|
104
|
-
this.count--
|
|
105
|
-
|
|
106
|
-
return this.items[index]
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Alias of {@link Deque.pop}
|
|
111
|
-
* @returns {?T} Returns the popped item.
|
|
112
|
-
*/
|
|
113
|
-
remove() {
|
|
114
|
-
return this.pop()
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Removes and returns the element at the beginning of the deque.
|
|
119
|
-
* @returns {?T} Returns the removed deque element.
|
|
120
|
-
*/
|
|
121
|
-
popleft() {
|
|
122
|
-
if (this.count === 0) return
|
|
123
|
-
|
|
124
|
-
const index = this.start
|
|
125
|
-
|
|
126
|
-
this.count--
|
|
127
|
-
this.start++
|
|
128
|
-
|
|
129
|
-
if (this.start === this.capacity) this.start = 0
|
|
130
|
-
|
|
131
|
-
return this.items[index]
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Returns the element at the beginning of the deque.
|
|
136
|
-
* @returns {?T} The element if exists
|
|
137
|
-
*/
|
|
138
|
-
first() {
|
|
139
|
-
if (this.count === 0) return
|
|
140
|
-
|
|
141
|
-
return this.items[this.start]
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Returns the element at a specified index position in the deque.
|
|
146
|
-
* @param {number} index The given index
|
|
147
|
-
* @returns {?T} The element if exists
|
|
148
|
-
*/
|
|
149
|
-
get(index) {
|
|
150
|
-
if (this.count === 0) return
|
|
151
|
-
|
|
152
|
-
index = this.start + index
|
|
153
|
-
if (index < 0) index += this.count
|
|
154
|
-
|
|
155
|
-
if (index > this.capacity) index -= this.capacity
|
|
156
|
-
|
|
157
|
-
return this.items[index]
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Update the element at a given `index`.
|
|
162
|
-
* @param {number} index The given index
|
|
163
|
-
*/
|
|
164
|
-
set(index: number, value: T) {
|
|
165
|
-
if (index < 0) index += this.count
|
|
166
|
-
if (index > this.count) throw new KeyError(`Invalid index: ${index} not in Deque.`)
|
|
167
|
-
this.items[index] = value
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Check if a given element is in the deque.
|
|
172
|
-
* @param {T} x The value to find
|
|
173
|
-
* @returns {boolean} `true` if the value is found
|
|
174
|
-
*/
|
|
175
|
-
contains(x) {
|
|
176
|
-
for (const value of this.values()) {
|
|
177
|
-
if (eq(x, value)) return true
|
|
178
|
-
}
|
|
179
|
-
return false
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Returns the first element that matches the `iteratee` function.
|
|
184
|
-
* @param {Iteratee<T>} iteratee A function that will be invoked per element
|
|
185
|
-
* @returns {?T} The element if exists
|
|
186
|
-
*/
|
|
187
|
-
find(iteratee: Iteratee<T>) {
|
|
188
|
-
for (const [key, value] of this.entries()) {
|
|
189
|
-
if (iteratee(value, key, this)) return value
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* Calls `iteratee` function for every element in the deque.
|
|
195
|
-
* @param {Iteratee<T>} iteratee A function that will be invoked per element
|
|
196
|
-
*/
|
|
197
|
-
forEach(iteratee) {
|
|
198
|
-
const c = this.capacity
|
|
199
|
-
const l = this.count
|
|
200
|
-
let i = this.start
|
|
201
|
-
let j = 0
|
|
202
|
-
|
|
203
|
-
while (j < l) {
|
|
204
|
-
iteratee(this.items[i], j, this)
|
|
205
|
-
i++
|
|
206
|
-
j++
|
|
207
|
-
|
|
208
|
-
if (i === c) i = 0
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Returns a new array with all the elements in reverse order.
|
|
214
|
-
* @returns {Array<T>} The elements reversed
|
|
215
|
-
*/
|
|
216
|
-
reversed() {
|
|
217
|
-
return this.toArray().reverse()
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* Returns a new array with all the elements in the order they were added to the deque.
|
|
222
|
-
* @returns {Array<T>} The elements array
|
|
223
|
-
*/
|
|
224
|
-
toArray() {
|
|
225
|
-
// Optimization
|
|
226
|
-
const offset = this.start + this.count
|
|
227
|
-
|
|
228
|
-
if (offset < this.capacity) return this.items.slice(this.start, offset)
|
|
229
|
-
|
|
230
|
-
const array = new this.ArrayConstructor(this.count)
|
|
231
|
-
const c = this.capacity
|
|
232
|
-
const l = this.count
|
|
233
|
-
let i = this.start
|
|
234
|
-
let j = 0
|
|
235
|
-
|
|
236
|
-
while (j < l) {
|
|
237
|
-
array[j] = this.items[i]
|
|
238
|
-
i++
|
|
239
|
-
j++
|
|
240
|
-
|
|
241
|
-
if (i === c) i = 0
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
return array
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* Returns an iterator over the deque's values.
|
|
249
|
-
* @returns {Iterator}
|
|
250
|
-
*/
|
|
251
|
-
values(): Iterable<T> {
|
|
252
|
-
const items = this.items
|
|
253
|
-
const c = this.capacity
|
|
254
|
-
const l = this.count
|
|
255
|
-
let i = this.start
|
|
256
|
-
let j = 0
|
|
257
|
-
|
|
258
|
-
return IterableIterator(() => {
|
|
259
|
-
if (j >= l)
|
|
260
|
-
return {
|
|
261
|
-
done: true
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
const value = items[i]
|
|
265
|
-
|
|
266
|
-
i++
|
|
267
|
-
j++
|
|
268
|
-
|
|
269
|
-
if (i === c) i = 0
|
|
270
|
-
|
|
271
|
-
return {
|
|
272
|
-
value,
|
|
273
|
-
done: false
|
|
274
|
-
}
|
|
275
|
-
})
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* Alias of {@link Deque.values}. Returns iterator of values.
|
|
280
|
-
*/
|
|
281
|
-
keys() {
|
|
282
|
-
return this.values()
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
/**
|
|
286
|
-
* Creates an iterator of `[index, value]` pairs for all elements in the deque.
|
|
287
|
-
* @returns {Iterator}
|
|
288
|
-
*/
|
|
289
|
-
entries() {
|
|
290
|
-
const items = this.items
|
|
291
|
-
const c = this.capacity
|
|
292
|
-
const l = this.count
|
|
293
|
-
let i = this.start
|
|
294
|
-
let j = 0
|
|
295
|
-
|
|
296
|
-
return IterableIterator<[number, T]>(() => {
|
|
297
|
-
if (j >= l)
|
|
298
|
-
return {
|
|
299
|
-
done: true
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
const value = items[i]
|
|
303
|
-
|
|
304
|
-
i++
|
|
305
|
-
|
|
306
|
-
if (i === c) i = 0
|
|
307
|
-
|
|
308
|
-
return {
|
|
309
|
-
value: [j++, value],
|
|
310
|
-
done: false
|
|
311
|
-
}
|
|
312
|
-
})
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
[Symbol.iterator]() {
|
|
316
|
-
return this.values()
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
[Symbol.for('nodejs.util.inspect.custom')]() {
|
|
320
|
-
return this.inspect()
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
// This is just for debugging in nodejs
|
|
324
|
-
inspect() {
|
|
325
|
-
const array = this.toArray()
|
|
326
|
-
|
|
327
|
-
array.type = this.ArrayConstructor.name
|
|
328
|
-
array.capacity = this.capacity
|
|
329
|
-
|
|
330
|
-
// Trick so that node displays the name of the constructor
|
|
331
|
-
Object.defineProperty(array, 'constructor', {
|
|
332
|
-
value: Deque,
|
|
333
|
-
enumerable: false
|
|
334
|
-
})
|
|
335
|
-
|
|
336
|
-
return array
|
|
337
|
-
}
|
|
338
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
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
|
-
}
|