solists 0.2.0 → 0.3.0
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/LICENSE +22 -0
- package/README.md +16 -6
- package/dist/DoublyLinkedList.js +3 -14
- package/package.json +8 -7
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2023 Emmanuel Ferdman
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
|
4
|
+
obtaining a copy of this software and associated documentation
|
|
5
|
+
files (the "Software"), to deal in the Software without
|
|
6
|
+
restriction, including without limitation the rights to use,
|
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the
|
|
9
|
+
Software is furnished to do so, subject to the following
|
|
10
|
+
conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be
|
|
13
|
+
included in all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://github.com/emmanuel-ferdman/solists">
|
|
3
|
+
<picture>
|
|
4
|
+
<img src="img/logo.png" height="128">
|
|
5
|
+
</picture>
|
|
6
|
+
</a>
|
|
7
|
+
</p>
|
|
2
8
|
|
|
3
9
|
The library provides a powerful and flexible implementation of the [self-organizing list](https://en.wikipedia.org/wiki/Self-organizing_list) data structure written in TypeScript. It offers support for multiple heuristic algorithms such as [Frequency Count](#Frequency-Count), [Move to Front](#Move-to-Front) and [Transpose](#Transpose). In addition to custom methods, the data structure also includes a selection of methods with behavior equivalent to that of JavaScript's built-in [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) data structure.
|
|
4
10
|
|
|
@@ -47,10 +53,10 @@ At the t-th item selection:
|
|
|
47
53
|
### Rearrange upon creation
|
|
48
54
|
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.
|
|
49
55
|
|
|
50
|
-
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 `
|
|
56
|
+
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.
|
|
51
57
|
|
|
52
58
|
Methods which perform rearrange of the list:
|
|
53
|
-
- Rearrange upon search: `at()`, `find()`, `findIndex()`, `findLast()`, `findLastIndex()`, `includes()`, `indexOf()` and `lastIndexOf`.
|
|
59
|
+
- Rearrange upon search: `at()`, `find()`, `findIndex()`, `findLast()`, `findLastIndex()`, `includes()`, `indexOf()` and `lastIndexOf()`.
|
|
54
60
|
- Rearrange upon creation: `constructor` (initialization from an iterable), `insert()`, `push()` and `unshift()`.
|
|
55
61
|
|
|
56
62
|
## Installation
|
|
@@ -139,8 +145,8 @@ List of methods of SoList:
|
|
|
139
145
|
|`includes()`|Determines whether a SoList includes a certain value among its entries|
|
|
140
146
|
|`indexOf()`|Returns the first index at which a given element can be found in a SoList|
|
|
141
147
|
|`insert()`|Adds an element into a specific index of a SoList|
|
|
142
|
-
|`isEqual()`|Checks if the SoList is equal to a given iterable|
|
|
143
148
|
|`isEmpty()`|Checks if the SoList does not contain any elements|
|
|
149
|
+
|`isEqual()`|Checks if the SoList is equal to a given iterable|
|
|
144
150
|
|`join()`|Joins all elements of SoList into a string separated by commas or a specified separator string|
|
|
145
151
|
|`keys()`|Returns a SoList iterator object of keys|
|
|
146
152
|
|`lastIndexOf()`|Returns the last index at which a given element can be found in a SoList|
|
|
@@ -166,7 +172,7 @@ Although SoList implements most of the methods of JS-Array (with identical behav
|
|
|
166
172
|
- Unlike JS-Array, SoList does not support empty items (for example `[1,,3]`).
|
|
167
173
|
- Currently, the `every()`, `filter()`, `find()`, `findIndex()`, `findLast()`, `findLastIndex()`, `flatMap()` and `some()` don't support the `thisArg` argument.
|
|
168
174
|
- Unsupported JS-Array methods: `group()` and `groupToMap()`.
|
|
169
|
-
- Additional custom methods of SoList: `insert()`, `
|
|
175
|
+
- Additional custom methods of SoList: `insert()`, `isEmpty()`, `isEqual()` and `remove()`.
|
|
170
176
|
|
|
171
177
|
## Contributing
|
|
172
178
|
|
|
@@ -176,4 +182,8 @@ Please make sure to update tests as appropriate and run existing ones using:
|
|
|
176
182
|
|
|
177
183
|
```
|
|
178
184
|
npm run test
|
|
179
|
-
```
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## License
|
|
188
|
+
|
|
189
|
+
The library is freely distributable under the terms of the [MIT license](LICENSE).
|
package/dist/DoublyLinkedList.js
CHANGED
|
@@ -379,7 +379,7 @@ class DoublyLinkedList {
|
|
|
379
379
|
}
|
|
380
380
|
const deleted = new DoublyLinkedList();
|
|
381
381
|
if (this.length > 0 && deleteCount > 0) {
|
|
382
|
-
|
|
382
|
+
const prev = this._getNode(start - 1);
|
|
383
383
|
let current = prev ? prev.next : this.head;
|
|
384
384
|
for (let index = 0; index < deleteCount; index += 1) {
|
|
385
385
|
deleted.push(current.value);
|
|
@@ -388,7 +388,6 @@ class DoublyLinkedList {
|
|
|
388
388
|
}
|
|
389
389
|
if (prev === null) {
|
|
390
390
|
this.head = current;
|
|
391
|
-
prev = current;
|
|
392
391
|
if (current) {
|
|
393
392
|
current.prev = null;
|
|
394
393
|
}
|
|
@@ -441,20 +440,10 @@ class DoublyLinkedList {
|
|
|
441
440
|
for (const [index, node] of this._nodes(0, this.length)) {
|
|
442
441
|
const value = node.value == null ? "" : node.value;
|
|
443
442
|
if (index !== this.length - 1) {
|
|
444
|
-
|
|
445
|
-
result = result.concat(value.toLocaleString()) + separator;
|
|
446
|
-
}
|
|
447
|
-
else {
|
|
448
|
-
result = result.concat(value.toLocaleString(locales, options)) + separator;
|
|
449
|
-
}
|
|
443
|
+
result = result.concat(value.toLocaleString(locales, options)) + separator;
|
|
450
444
|
}
|
|
451
445
|
else {
|
|
452
|
-
|
|
453
|
-
result = result.concat(value.toLocaleString());
|
|
454
|
-
}
|
|
455
|
-
else {
|
|
456
|
-
result = result.concat(value.toLocaleString(locales, options));
|
|
457
|
-
}
|
|
446
|
+
result = result.concat(value.toLocaleString(locales, options));
|
|
458
447
|
}
|
|
459
448
|
}
|
|
460
449
|
return result;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "solists",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Implementation of self-organizing lists",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -20,19 +20,20 @@
|
|
|
20
20
|
"self-organizing-list"
|
|
21
21
|
],
|
|
22
22
|
"author": "Emmanuel Ferdman",
|
|
23
|
-
"license": "
|
|
23
|
+
"license": "MIT",
|
|
24
24
|
"bugs": {
|
|
25
25
|
"url": "https://github.com/emmanuel-ferdman/solists/issues"
|
|
26
26
|
},
|
|
27
27
|
"homepage": "https://github.com/emmanuel-ferdman/solists#readme",
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
30
|
-
"@typescript-eslint/parser": "^5.
|
|
31
|
-
"eslint": "^8.
|
|
29
|
+
"@typescript-eslint/eslint-plugin": "^7.5.0",
|
|
30
|
+
"@typescript-eslint/parser": "^7.5.0",
|
|
31
|
+
"eslint": "^8.57.0",
|
|
32
|
+
"mocha": "^10.4.0",
|
|
32
33
|
"nyc": "^15.1.0",
|
|
33
34
|
"ts-mocha": "^10.0.0",
|
|
34
|
-
"ts-node": "^10.9.
|
|
35
|
-
"typescript": "^4.
|
|
35
|
+
"ts-node": "^10.9.2",
|
|
36
|
+
"typescript": "^5.4.3"
|
|
36
37
|
},
|
|
37
38
|
"files": [
|
|
38
39
|
"dist"
|