-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
1364 lines (1346 loc) · 33.4 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/** Represents an absent value */
declare const NO_VALUE: symbol;
/** Absent value placeholder */
type AbsentValue = typeof NO_VALUE;
/**
* Describes a container having a length.
*/
declare abstract class HasLength {
constructor();
/**
* Returns length of the underlying container.
*/
abstract len(): number;
/**
* Returns `true` if the underlying container is empty (has zero length).
*/
isEmpty(): boolean;
}
/**
* Describes a container having both capacity and length.
*/
declare abstract class HasCapacity extends HasLength {
_capacity: number;
/**
* Creates a new container with supplied capacity.
* In case capacity is equal to zero, an error will be thrown.
* @param capacity
*/
constructor(capacity: number);
/**
* Returns capacity of the underlying container.
*
*
*/
capacity(): number;
/**
* Returns `true` if the length of the underlying container reached its capacity.
*
*
*/
isFull(): boolean;
/**
* Returns `true` if the length of the underlying container will reach (or already reached) its capacity.
*
*
*/
willBeFull(): boolean;
}
/**
* Destructable entity.
*/
interface Destroyable {
/**
* Drops all references to the supplied entity.
*/
destroy(): void;
}
/**
* Clearable entity.
*/
interface Clearable {
/**
* Removes all entities from the underlying storage.
*/
clear(): void;
}
/**
* Parent able to drop an item with the supplied key.
*/
interface Parent<K> {
/**
* Drops an item corresponding to the supplied key.
* @param key
*/
drop(key: K): void;
}
/**
* The path from the parent to the child.
* If the key is a `NO_VALUE`, then the child is stored under the key equal to itself.
*/
declare class ParentPath<K> {
/**
* Parent.
*/
parent: Parent<K>;
/**
* The key under which the child is stored.
* If it's a `NO_VALUE`, then the child is stored under the key identical to itself.
*/
key: K | AbsentValue;
constructor(parent: Parent<K>, key: K | AbsentValue);
drop(child: K): void;
}
/**
* Contains removed/added entities.
*/
declare class Result<V> {
removed: Iterable<V>;
added: Iterable<V>;
static EMPTY_RESULT: Result<unknown>;
private constructor();
/** Creates a result containing added entities */
static added<V>(added: Iterable<V>): Result<V>;
/** Creates a result containing removed entities */
static removed<V>(removed: Iterable<V>): Result<V>;
/**
* Creates a result containing removed and added entities.
* @param removed
* @param added
*/
static removedAdded<V>(removed: Iterable<V>, added: Iterable<V>): Result<V>;
/**
* Creates an empty result.
*/
static empty<V>(): Result<V>;
/**
* Appends remove/added items from the supplied result to the current result.
* @param result
*/
chain(result: Result<V>): Result<V>;
/**
* Executes given function for each added item.
* @param fn
*
*/
forEachAdded(fn: (added: V) => void): this;
/**
* Executes given function for each removed item.
* @param fn
*
*/
forEachRemoved(fn: (removed: V) => void): this;
}
/**
* Describes some strategy holding up to `capacity` items at the same moment.
*/
declare abstract class CacheStrategy<V>
extends HasCapacity
implements Clearable, Parent<V>
{
constructor(capacity: number);
/**
* Records write access of the supplied item.
* @param value
*
*/
abstract write(value: V): Result<V>;
/**
* Records read access of the supplied item. Throws an error if an item doesn't exist.
* @param value
*
*/
abstract read(value: V): Result<V>;
/**
* Removes supplied item from the queue.
* @param value
*
*/
abstract drop(value: V): boolean;
/**
* Removes an item from the beginning of the queue.
* Returns either item or `NO_VALUE` if queue is empty.
*/
abstract take(): V | AbsentValue;
/**
* Peeks a value from the beginning of the queue.
* Returns either item or `NO_VALUE` if queue is empty.
*
*/
abstract peek(): V | AbsentValue;
/**
* Returns `true` if given item exists in the queue.
* @param value
*
*/
abstract has(value: V): boolean;
/**
* Removes all items from the strategy.
*
*/
clear(): void;
/**
* Reserves place for a new item.
* @param value
*/
protected reservePlace(): Result<V>;
}
/**
* `CacheStrategy` with implemented abstract methods.
*/
type CacheStrategyClass<V> = new (...args: any[]) => CacheStrategy<V> & {
len(): number;
write(value: V): Result<V>;
read(value: V): Result<V>;
drop(value: V): boolean;
take(): V | AbsentValue;
peek(): V | AbsentValue;
has(value: V): boolean;
};
/**
* Key-value storage.
*/
declare abstract class Storage<K, V>
extends HasLength
implements Destroyable, Clearable, Parent<K>
{
/**
* Paths from parents to the given storage.
*/
parentPaths: Iterable<ParentPath<K | Storage<K, V>>>;
/**
* Parameters.
*/
params: StorageParams<K, V>;
destroyed: boolean;
constructor(
params?: StorageParams<K, V>,
parentPaths?: Iterable<ParentPath<K | Storage<K, V>>>
);
/**
* Calls a `destroy` implementation that will unlink given storage from all entities
* referencing it.
*
*/
destroy(): void;
/**
* Returns `true` if supplied key is weak, and thus won't be stored directly.
* @param key
*/
isWeak(_key: K): boolean;
/**
* Returns `true` if value associated with the given key exists.
* @param key
*
*/
has(key: K): boolean;
/**
* Retrieves an item corresponding to the supplied key.
* @param key
*
*/
abstract get(key: K): V | AbsentValue;
/**
* Associates supplied item with the key.
* @param key
* @param value
*
*/
abstract set(key: K, value: V): void;
/**
* Drops an item corresponding to the supplied key.
* @param key
*
*/
abstract drop(key: K): V | AbsentValue;
/**
* Removes all items from the storage.
*
*/
abstract clear(): void;
/**
* Returns an iterator over the entries.
*
*/
abstract entries(): Iterable<{
key: K;
value: V;
}>;
}
/**
* Storage callbacks.
*/
interface StorageParams<K, V> {
/**
* Callback to be called on the storage creation.
* @param storage
*/
onCreateStorage?: (storage: Storage<K, V>) => void;
/**
* Callback to be called on the storage removal.
* @param storage
*/
onRemoveStorage?: (storage: Storage<K, V>) => void;
}
/**
* Leaf storage callbacks.
*/
interface LeafStorageParams<K, V> extends StorageParams<K, V> {
/** Callback to be called on the leaf creation */
onCreateLeaf?: (leafKey: K) => void;
/** Callback to be called on the leaf removal */
onRemoveLeaf?: (leafKey: K) => void;
}
/**
* Stores leaf key -> value pairs.
*/
declare class LeafStorage<K, V> extends Storage<K, V> {
params: LeafStorageParams<K, V>;
storage: Storage<K, V>;
strategy: CacheStrategy<K>;
dropStorageValue: (key: K) => boolean;
constructor(
storage: Storage<K, V>,
strategy: CacheStrategy<K>,
params: LeafStorageParams<K, V>,
parentPaths?: Iterable<ParentPath<K | LeafStorage<K, V>>>
);
/**
* Returns amount of keys (references) stored in a map.
*
*/
len(): number;
/**
* Drops an item corresponding to the supplied key.
* @param key
*
*/
drop(key: K): V | AbsentValue;
/**
* Retrieves an item corresponding to the supplied key.
* @param key
*
*/
get(key: K): V | AbsentValue;
/**
* Associates supplied item with the key.
* @param key
* @param value
*
*/
set(key: K, value: V): void;
/**
* Removes an item from the beginning of the queue.
*
*/
take(): K | AbsentValue;
/**
* Removes all items from the storage and cache strategy.
*
*/
clear(): void;
/**
* Returns an iterator over the entries.
*
*/
entries(): Iterable<{
key: K;
value: V;
}>;
/**
* Executes callbacks for each added/removed item.
* @param result
*/
private handleResult;
}
/** Parameters for the `UnifiedStorage` */
interface UnifiedStorageParams<K, V> extends StorageParams<K, V> {
/** Denotes if the object storage must be used for values with primitive keys */
useObjectStorage?: boolean;
/** Denotes if the weak storage must be used for values with non-primitive keys */
useWeakStorage?: boolean;
}
/**
* Either leaf storage or nested storage containing either nested storages or leaf storages.
*/
type NestedStorage<K, V> =
| LeafStorage<K, V>
| Storage<K, NestedStorage<K, V> | LeafStorage<K, V> | V>;
/**
* Params for the storage context.
*/
interface Params<K, V>
extends UnifiedStorageParams<K, V>,
LeafStorageParams<K, V>,
StorageParams<K, V> {
/**
* Total limit for the storages (cache nodes).
*/
totalStoragesLimit?: number;
/**
* Total limit for the leaves (cache entries). Default is 10000.
*/
totalLeavesLimit?: number;
/**
* Limit of the leaves per a single leaf storage.
*/
leavesPerStorageLimit?: number;
/**
* Total limit of the leaf storages.
*/
totalLeafStoragesLimit?: number;
/**
* Either strategy class or different strategy classes for leaves and storage nodes.
*/
strategy?:
| StrategyConfig<K, V>
| CacheStrategyClass<K | LeafStorage<K, V> | NestedStorage<K, V>>;
}
/**
* Config for the leaf and storage cache strategies.
*/
type StrategyConfig<K, V> = {
leafStrategyClass: CacheStrategyClass<K | LeafStorage<K, V>>;
storageStrategyClass: CacheStrategyClass<NestedStorage<K, V>>;
};
/** Params interface extended with optional length and checkLast flag */
interface ParamsWithLength<K, V> extends Params<K, V> {
/** Overrides function length */
length?: number;
/** Check last arguments or not (default to `true`) */
checkLast?: boolean;
}
/**
* Memoizes provided function returning wrapped version of it.
* Result function will return value without calling the supplied function if it's present in the cache for the supplied arguments according to `Same-value-zero` algorithm.
* If no value is found, the underlying function will be called with provided arguments.
* @param func
* @param params
*/
declare function memoize<V>(
func: (...args: any[]) => V,
{ length: depth, checkLast, ...params }?: ParamsWithLength<any, V>
): typeof func & {
recomputations: number;
};
/**
* Creates memoized selector. If last argument is an object, it will be treated as configuration.
*/
declare const createMemoizedSelector: (...params: any[]) => Function;
/**
* @abstract
* An ordered collection of items which can be walked in two directions.
*/
declare abstract class OrderedCollection<
Value,
Item,
Absent = AbsentValue
> extends HasLength {
/**
* Adds an item to the end of the collection.
* Returns either created item or absent value in case value can't be added.
* @param value
*
*/
abstract pushBack(value: Value): Item | Absent;
/**
* Pushes an item to the beginning of the collection.
* Returns either created item or absent value in case value can't be added.
* @param value
*
*/
abstract pushFront(value: Value): Item | Absent;
/**
* Moves an item to the beginning of the collection.
* Returns `true` in case of success.
* @param item
*
*/
abstract moveFront(item: Item): boolean;
/**
* Moves an item to the back.
* Returns `true` in case of success.
* @param item
*
*/
abstract moveBack(item: Item): boolean;
/**
* Removes an item from the collection.
* Returns `true` in case of success.
*/
abstract remove(item: Item): boolean;
/**
* Returns `true` if supplied item belongs to the collection.
*/
abstract contains(item: Item): boolean;
/**
* Takes a value from the end of the collection.
*/
abstract takeBack(): Value | Absent;
/**
* Takes a value from the beginning of the collection.
*/
abstract takeFront(): Value | Absent;
/**
* Inserts given value after the supplied item returning new item.
* Returns `Absent` in case supplied item doesn't belong to this list.
*/
abstract insertAfter(item: Item, value: Value): Item | Absent;
/**
* Inserts given value before the supplied item returning new item.
* Returns `Absent` in case supplied item doesn't belong to this list.
*
*/
abstract insertBefore(item: Item, value: Value): Item | Absent;
/**
* Peeks a value from the end of the collection.
*/
abstract peekBack(): Value | Absent;
/**
* Peeks a value from the beginning of the collection.
*/
abstract peekFront(): Value | Absent;
/**
* Peeks an item from the beginning of the collection.
* Returns either item or `NO_VALUE` if collection is empty.
*/
abstract peekItemFront(): Item | Absent;
/**
* Peeks an item from the end of the collection.
* Returns either item or `NO_VALUE` if collection is empty.
*/
abstract peekItemBack(): Item | Absent;
/**
* Returns an iterator over collection values starting from the end.
*/
abstract valuesBack(): Iterable<Value>;
/**
* Returns an iterator over collection values starting from the beginning.
*/
abstract valuesFront(): Iterable<Value>;
}
/**
* @abstract
* An indexed ordered collection of items.
*
* **Item `->` Key** relation can be either one-to-one or one-to-many.
*/
declare abstract class IndexedOrderedCollection<
Key,
Value,
Item,
Absent = AbsentValue
> extends OrderedCollection<Value, Item, Absent> {
/**
* Retrieves an item associated with the provided key returning it.
* Returns `NO_VALUE` if the item with the given key didn't exist.
*/
abstract get(key: Key): Item | Absent;
/**
* Returns `true` if collection has an item associated with the provided key.
*/
abstract has(key: Key): boolean;
/**
* Drops an item associated with the provided key returning it.
* Returns `NO_VALUE` if the item with the given key didn't exist.
*/
abstract drop(key: Key): Value | Absent;
/**
* Drops an item's key from the collection. If referenced item has no more keys, it will be dropped as well.
* Returns `true` in case of a successful removal or `false` if the value wasn't found.
*/
abstract dropKey(key: Key): boolean;
/**
* An iterator over keys.
*/
abstract keys(): Iterable<Key>;
}
/**
* @abstract
* An indexed collection of items with ordered keys.
*
* **Item `->` Key** relation can be either one-to-one or one-to-many.
*/
declare abstract class IndexedOrderedCollectionWithOrderedKeys<
Key,
Value,
Item,
Absent = AbsentValue
> extends IndexedOrderedCollection<Key, Value, Item, Absent> {
/**
* Takes an item's key from the beginning of the collection. If referenced item has no more keys, it will be dropped.
*/
abstract takeKeyFront(): Key | Absent;
/**
* Takes an item's key from the end of the collection. If referenced item has no more keys, it will be dropped.
*/
abstract takeKeyBack(): Key | Absent;
/**
* Peeks a key from the beginning if the collection.
*/
abstract peekKeyFront(): Key | Absent;
/**
* Peeks a key from the end of the collection.
*/
abstract peekKeyBack(): Key | Absent;
/**
* Associates supplied key with the provided value.
* Key will be added to the beginning of the queue.
*/
abstract addKeyFront(key: Key, item: Item): boolean;
/**
* Associates supplied key with the provided value.
* Key will be added to the end of the queue.
*/
abstract addKeyBack(key: Key, item: Item): boolean;
/**
* Returns an iterator over underlying keys.
*/
abstract keysFront(): Iterable<Key>;
/**
* Returns an iterator over underlying keys.
*/
abstract keysBack(): Iterable<Key>;
keys(): Iterable<Key>;
}
/**
* A node of the double-ended linked list.
*/
declare class ListNode<T> implements Destroyable {
root: LinkedList<T> | null;
next: ListNode<T> | null;
prev: ListNode<T> | null;
value: T;
constructor(
value: T,
root: LinkedList<T>,
prev?: ListNode<T> | null,
next?: ListNode<T> | null
);
/**
* Inserts supplied value before the current node.
* @param value
*
*/
insertPrev(value: T): ListNode<T>;
/**
* Inserts supplied value after the current node.
* @param value
*
*/
insertNext(value: T): ListNode<T>;
/**
* Disconnects current node from its predecessor and successor.
*
*/
unlink(): void;
/**
* Disconnects current node from its predecessor, successor and root.
*
*/
destroy(): void;
}
/**
* Double-ended linked list.
*/
declare class LinkedList<T> extends OrderedCollection<T, ListNode<T>, null> {
length: number;
head: ListNode<T> | null;
tail: ListNode<T> | null;
constructor(values?: Iterable<T>);
/**
* Pushes an node to the back of the list.
* @param node
*
*/
pushBack(node: T): ListNode<T>;
/**
* Pushes an node to the front of the list.
* @param node
*
*/
pushFront(node: T): ListNode<T>;
/**
* Moves node to the front of the queue.
* Returns `false` if node doesn't belong to the given list.
* @param node
*
*/
moveFront(node: ListNode<T>): boolean;
/**
* Moves node to the back of the queue.
* Returns `false` if node doesn't belong to the given list.
* @param node
*
*/
moveBack(node: ListNode<T>): boolean;
/**
* Peeks a value from the front of the queue.
* Returns either item or `null` if queue is empty.
*
*/
peekFront(): T | null;
/**
* Peeks a value from the back of the queue.
* Returns either item or `null` if queue is empty.
*
*/
peekBack(): T | null;
/**
* Peeks an item from the front of the queue.
* Returns either item or `null` if queue is empty.
*
*/
peekItemFront(): ListNode<T> | null;
/**
* Peeks an item from the end of the queue.
* Returns either item or `null` if queue is empty.
*
*/
peekItemBack(): ListNode<T> | null;
/**
* Takes a value from the back of the queue.
* Returns either item or `null` if queue is empty.
*
*/
takeBack(): T | null;
/**
* Takes front node from the list.
* Returns `null` if list has no nodes.
*
*/
takeFront(): T | null;
/**
* Inserts given value after the supplied raw linked list node.
* Returns `null` in case supplied node doesn't belong to this list.
* @param node
* @param value
*
*/
insertAfter(node: ListNode<T>, value: T): ListNode<T> | null;
/**
* Inserts given value before the supplied raw linked list node.
* Returns `null` in case supplied node doesn't belong to this list.
* @param node
* @param value
*
*/
insertBefore(node: ListNode<T>, value: T): ListNode<T>;
/**
* Returns `true` if supplied node belongs to the list.
* @param node
*/
contains(node: ListNode<T>): boolean;
/**
* Removes given node from the list.
* Returns `false` if node doesn't belong to the given list.
* @param node
*/
remove(node: ListNode<T>): boolean;
/**
* Returns amount of items stored in the list.
*
*/
len(): number;
/**
* Returns an iterator over collection values starting from the end.
*/
valuesBack(): Iterable<T>;
/**
* Returns an iterator over collection values starting from the beginning.
*/
valuesFront(): Iterable<T>;
}
/**
* An indexed queue where each item is an indexed queue of keys.
* A value itself should implement `IndexedOrderedCollection`.
*/
declare class MultiKeyQueue<
Key,
Value extends IndexedOrderedCollection<Key, Key, InnerItem>,
InnerItem = Key
> extends IndexedOrderedCollectionWithOrderedKeys<Key, Value, ListNode<Value>> {
list: LinkedList<Value>;
map: Storage<Key, ListNode<Value>>;
constructor(values?: Iterable<Value>);
/**
* Returns amount of keys (references) stored in a map.
*
*/
len(): number;
/**
* Drops an item associated with the supplied key.
* Returns dropped value in case of a successful drop or `NO_VALUE` if the value wasn't found.
* @param key
*
*/
drop(key: Key): Value | AbsentValue;
/**
* Moves node to the front of the queue.
* Returns `true` in case of success.
* @param listNode
*
*/
moveFront(listNode: ListNode<Value>): boolean;
/**
* Moves node to the back of the queue.
* Returns `true` in case of success.
* @param listNode
*
*/
moveBack(listNode: ListNode<Value>): boolean;
/**
* Removes an item from the queue.
* Returns `true` in case of success.
* @param listNode
*
*/
remove(listNode: ListNode<Value>): boolean;
/**
* Returns `true` if supplied item belongs to the collection.
*/
contains(listNode: ListNode<Value>): boolean;
/**
* Drops supplied key from the map.
* Item belonging to this key will be deleted only if it has no more references in the map.
* Returns `true` in case of a successful removal or `false` if the value wasn't found.
* @param key
*
*/
dropKey(key: Key): boolean;
/**
* Inserts given value after the supplied raw linked list node.
* @param node
* @param key
*
*/
insertAfter(
node: ListNode<Value>,
value: Value
): ListNode<Value> | AbsentValue;
/**
* Inserts given value before the supplied raw linked list node.
* @param node
* @param key
*
*/
insertBefore(
node: ListNode<Value>,
value: Value
): ListNode<Value> | AbsentValue;
/**
* Returns value associated with the given key or `NO_VALUE` if the value wasn't found.
* @param key
*
*/
get(key: Key): ListNode<Value> | AbsentValue;
/**
* Returns `true` if value associated with the given key exists.
* @param key
*
*/
has(node: Key): boolean;
/**
* Adds a key for the supplied item to the beginning of its queue.
* @param key
* @param listNode
*
*/
addKeyFront(key: Key, item: ListNode<Value>): boolean;
/**
* Adds a key for the supplied item to the end of its queue.
* @param key
* @param listNode
*
*/
addKeyBack(key: Key, item: ListNode<Value>): boolean;
/**
* Takes a value from the beginning of the queue.
* Returns either item or `NO_VALUE` if queue is empty.
*/
takeFront(): Value | AbsentValue;
/**
* Takes a value from the end of the queue.
* Returns either item or `NO_VALUE` if queue is empty.
*/
takeBack(): Value | AbsentValue;
/**
* Peeks a value from the beginning of the queue.
* Returns either item or `NO_VALUE` if queue is empty.
*
*/
peekFront(): Value | AbsentValue;
/**
* Peeks a value from the end of the queue.
* Returns either item or `NO_VALUE` if queue is empty.
*
*/
peekBack(): Value | AbsentValue;
/**
* Peeks an item from the beginning of the collection.
* Returns either item or `NO_VALUE` if queue is empty.
*/
peekItemFront(): AbsentValue | ListNode<Value>;
/**
* Peeks an item from the end of the collection.
* Returns either item or `NO_VALUE` if queue is empty.
*/
peekItemBack(): AbsentValue | ListNode<Value>;
/**
* Peeks a key of the item from the beginning of the queue.
* Returns either key or `NO_VALUE` if queue is empty.
*
*/
peekKeyFront(): Key | AbsentValue;
/**
* Peeks a key of the item from the end of the queue.
* Returns either key or `NO_VALUE` if queue is empty.
*
*/
peekKeyBack(): Key | AbsentValue;
/**
* Takes a key of the item from the beginning of the queue.
* Returns either key or `NO_VALUE` if queue is empty.
*
*/
takeKeyFront(): Key | AbsentValue;
/**
* Takes a key of the item from the end of the queue.
* Returns either key or `NO_VALUE` if queue is empty.
*
*/
takeKeyBack(): Key | AbsentValue;
/**
* Returns an iterator over values.
*
*/
valuesFront(): Iterable<Value>;
/**
* Returns an iterator over values.
*
*/
valuesBack(): Iterable<Value>;
/**
* Returns an iterator over keys starting from the beginning.
*
*/
keysFront(): Iterable<Key>;
/**
* Returns an iterator over keys starting from the end.
*
*/
keysBack(): Iterable<Key>;
/**
* Pushes an item to the end of the queue.
* @param value
*
*/
pushBack(value: Value): ListNode<Value>;
/**
* Pushes an item to the beginning of the queue.
* @param value
*
*/
pushFront(value: Value): ListNode<Value>;
/**
* Associates keys of the provided value with the supplied raw linked list node.
* @param value
* @param node
*
*/
private assocKeys;
/**
* Dissociates keys of the provided value.
* @param value
* @param node
*
*/
private dissocKeys;
}
/**
* Wrapper class which represents ordered indexed collection with a single item.
*/
declare class Single<V> extends IndexedOrderedCollectionWithOrderedKeys<
V,
V,
V
> {
value: V | AbsentValue;
constructor(value: V);
pushFront(value: V): V | AbsentValue;
pushBack(value: V): V | AbsentValue;
takeKeyFront(): V | AbsentValue;
takeKeyBack(): V | AbsentValue;
peekKeyFront(): V | AbsentValue;
peekKeyBack(): V | AbsentValue;
peekItemFront(): V | AbsentValue;
peekItemBack(): V | AbsentValue;
addKeyFront(_key: V, _item: V): boolean;
addKeyBack(_key: V, _item: V): boolean;
dropKey(value: V): boolean;
get(value: V): V | AbsentValue;
keysFront(): Iterable<V>;
keysBack(): Iterable<V>;
takeFront(): V | AbsentValue;
takeBack(): V | AbsentValue;
insertAfter(_item: V, _value: V): V | AbsentValue;
insertBefore(_item: V, _value: V): V | AbsentValue;
contains(item: V): boolean;