You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+62-53Lines changed: 62 additions & 53 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ The library provides a powerful and flexible implementation of the [self-organiz
10
10
11
11
## Introduction
12
12
13
-
A *self-organizing list* (aka *SoList*) is a list that reorders its elements based on some self-organizing heuristic to improve average access time. The aim of a self-organizing list is to improve efficiency of linear search by moving more frequently accessed items towards the head of the list. A self-organizing list achieves near constant time for element access in the best case. A self-organizing list uses a reorganizing algorithm to adapt to various query distributions at runtime.
13
+
A _self-organizing list_ (aka _SoList_) is a list that reorders its elements based on some self-organizing heuristic to improve average access time. The aim of a self-organizing list is to improve efficiency of linear search by moving more frequently accessed items towards the head of the list. A self-organizing list achieves near constant time for element access in the best case. A self-organizing list uses a reorganizing algorithm to adapt to various query distributions at runtime.
14
14
15
15
### Self-organizing techniques
16
16
@@ -19,6 +19,7 @@ A *self-organizing list* (aka *SoList*) is a list that reorders its elements bas
19
19
This technique involves counting the number of times each node is searched for, by keeping a separate counter variable for each node that is incremented every time the node is accessed.
20
20
21
21
Pseudocode:
22
+
22
23
```
23
24
init: count(i) = 0 for each item i
24
25
At t-th item selection:
@@ -32,6 +33,7 @@ At t-th item selection:
32
33
This technique moves the node which is accessed to the head of the list.
33
34
34
35
Pseudocode:
36
+
35
37
```
36
38
At the t-th item selection:
37
39
if item i is selected:
@@ -40,9 +42,10 @@ At the t-th item selection:
40
42
41
43
#### Transpose
42
44
43
-
This technique involves swapping an accessed node with its predecessor.
45
+
This technique involves swapping an accessed node with its predecessor.
44
46
45
47
Pseudocode:
48
+
46
49
```
47
50
At the t-th item selection:
48
51
if item i is selected:
@@ -51,41 +54,45 @@ At the t-th item selection:
51
54
```
52
55
53
56
### Rearrange upon creation
57
+
54
58
In literature, some self-organizing list implementations activate a heuristic after every creation operation (like `insert()`, `push()`, `unshift()`, etc.). This means that immediately after a new node is added to the list, the relevant heuristic is triggered and the list is rearranged.
55
59
56
60
This library supports both of these approaches. By default, the list is only rearranged when searched. To activate the option for rearranging the list upon creation, use `rearrangeOnCreation=true` when creating a new SoList instance. See the example below for more details.
57
61
58
62
Methods which perform rearrange of the list:
63
+
59
64
- Rearrange upon search: `at()`, `find()`, `findIndex()`, `findLast()`, `findLastIndex()`, `includes()`, `indexOf()` and `lastIndexOf()`.
60
65
- Rearrange upon creation: `constructor` (initialization from an iterable), `insert()`, `push()` and `unshift()`.
|`solist[Symbol.iterator]()`|Returns an iterator that yields the value of each index in the SoList|
138
+
|`at()`|Returns the value at a given index|
139
+
|`concat()`|Returns a new SoList consisting of merging the existing SoList with given iterable inputs|
140
+
|`constructor`|Creates a new empty SoList instance or from a given iterable|
141
+
|`copyWithin()`|Shallow copies part of a SoList to another location in the same SoList and returns it|
142
+
|`entries()`|Returns a SoList iterator object of key/value pairs|
143
+
|`every()`|Checks if every element in a SoList satisfies a predicate function|
144
+
|`fill()`|Changes all elements in a SoList to a static value|
145
+
|`filter()`|Creates a new SoList with every element in a SoList that satisfies a predicate function|
146
+
|`find()`|Returns the value of the first element in a SoList that satisfies a predicate function|
147
+
|`findIndex()`|Returns the index of the first element in a SoList that satisfies a predicate function|
148
+
|`findLast()`|Returns the value of the last element in a SoList that satisfies a predicate function|
149
+
|`findLastIndex()`|Returns the index of the last element in a SoList that satisfies a predicate function|
150
+
|`flat()`|Creates a new SoList with all sub-SoList elements concatenated into it recursively up to the specified depth|
151
+
|`forEach()`|Executes a provided function once for each SoList element|
152
+
|`includes()`|Determines whether a SoList includes a certain value among its entries|
153
+
|`indexOf()`|Returns the first index at which a given element can be found in a SoList|
154
+
|`insert()`|Adds an element into a specific index of a SoList|
155
+
|`isEmpty()`|Checks if the SoList does not contain any elements|
156
+
|`isEqual()`|Checks if the SoList is equal to a given iterable|
157
+
|`join()`|Joins all elements of SoList into a string separated by commas or a specified separator string|
158
+
|`keys()`|Returns a SoList iterator object of keys|
159
+
|`lastIndexOf()`|Returns the last index at which a given element can be found in a SoList|
160
+
|`map()`|Creates a new SoList populated with the results of calling a provided function on every element of a SoList|
161
+
|`pop()`|Removes the last element from a SoList and returns that element|
162
+
|`push()`|Adds one or more elements to the end of a SoList and returns the new length of the SoList|
163
+
|`reduce()`|Reduces the values of a SoList to a single value (going left-to-right)|
164
+
|`reduceRight()`|Reduces the values of a SoList to a single value (going right-to-left)|
165
+
|`remove()`|Removes the element at a specific index from a SoList|
166
+
|`reverse()`|Reverses the order of the elements in a SoList|
167
+
|`shift()`|removes the first element from a SoList and returns that removed element|
168
+
|`slice()`|Returns a shallow copy of a portion of a SoList into a new SoList selected by positions|
169
+
|`some()`|Checks if any of the elements in a SoList satisfy a predicate function|
170
+
|`sort()`|Sorts the elements of a SoList and returns the reference to the same SoList, now sorted|
171
+
|`splice()`|Changes the contents of a SoList by removing or replacing existing elements and/or adding new elements|
172
+
|`toLocaleString()`|Returns a string representing the elements of the SoList using their `toLocaleString` methods|
173
+
|`toString()`|Returns a string representing the specified SoList and its elements|
174
+
|`unshift()`|Adds one or more elements to the beginning of a SoList and returns the new length of the SoList|
175
+
|`values()`|Returns a SoList iterator object of values|
169
176
170
177
## SoList vs JS-Array
178
+
171
179
Although SoList implements most of the methods of JS-Array (with identical behavior), there are several differences and limitations:
180
+
172
181
- Unlike JS-Array, SoList does not support empty items (for example `[1,,3]`).
173
182
- Currently, the `every()`, `filter()`, `find()`, `findIndex()`, `findLast()`, `findLastIndex()`, `flatMap()` and `some()` don't support the `thisArg` argument.
174
183
- Unsupported JS-Array methods: `group()` and `groupToMap()`.
0 commit comments