Skip to content

Commit 30e8312

Browse files
chore: add Prettier for code formatting
Signed-off-by: Emmanuel Ferdman <[email protected]>
1 parent ba49f16 commit 30e8312

File tree

95 files changed

+5463
-5341
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+5463
-5341
lines changed

.eslintrc.cjs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
module.exports = {
2-
"extends": ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
3-
"parser": '@typescript-eslint/parser',
4-
"plugins": ['@typescript-eslint'],
5-
"root": true,
6-
"rules": {
7-
"indent": ["error", 2],
8-
"prefer-rest-params": "off",
2+
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
3+
parser: "@typescript-eslint/parser",
4+
plugins: ["@typescript-eslint"],
5+
root: true,
6+
rules: {
7+
"@typescript-eslint/naming-convention": "warn",
98
"@typescript-eslint/no-explicit-any": "off",
109
"@typescript-eslint/no-non-null-assertion": "off",
11-
"@typescript-eslint/naming-convention": "warn",
12-
"no-plusplus": ["error", { "allowForLoopAfterthoughts": true }],
13-
"no-multiple-empty-lines": ["error", { "max": 1 }],
10+
"indent": ["error", 2],
11+
"no-multiple-empty-lines": ["error", { max: 1 }],
12+
"no-plusplus": ["error", { allowForLoopAfterthoughts: true }],
13+
"prefer-rest-params": "off",
14+
"semi": ["error", "always"],
1415
"sort-imports": "error",
15-
"semi": ["error", "always"]
16-
}
16+
},
1717
};

.github/workflows/test.yml

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
name: "Test Suite"
2-
3-
on:
4-
push:
5-
branches:
6-
- '**'
7-
pull_request:
8-
branches:
9-
- '**'
10-
11-
jobs:
12-
test:
13-
runs-on: ubuntu-latest
14-
strategy:
15-
matrix:
16-
# Based on https://nodejs.org/en/about/previous-releases
17-
node-version: [22.x, 24.x]
18-
steps:
19-
- name: Checkout repository
20-
uses: actions/checkout@v4
21-
22-
- name: Set up Node.js
23-
uses: actions/setup-node@v4
24-
with:
25-
node-version: ${{ matrix.node-version }}
26-
27-
- name: Install dependencies
28-
run: npm install
29-
30-
- name: Run tests
31-
run: npm run test
1+
name: "Test Suite"
2+
3+
on:
4+
push:
5+
branches:
6+
- "**"
7+
pull_request:
8+
branches:
9+
- "**"
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
strategy:
15+
matrix:
16+
# Based on https://nodejs.org/en/about/previous-releases
17+
node-version: [22.x, 24.x]
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
21+
22+
- name: Set up Node.js
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: ${{ matrix.node-version }}
26+
27+
- name: Install dependencies
28+
run: npm install
29+
30+
- name: Run tests
31+
run: npm run test

.prettierignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Build outputs
2+
dist
3+
4+
# Dependencies
5+
node_modules
6+
7+
# Generated files
8+
coverage
9+
.nyc_output
10+
11+
# Git
12+
.git

.prettierrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"arrowParens": "always",
3+
"bracketSpacing": true,
4+
"printWidth": 100,
5+
"quoteProps": "consistent",
6+
"semi": true,
7+
"singleQuote": false,
8+
"tabWidth": 2,
9+
"trailingComma": "es5"
10+
}

README.md

Lines changed: 62 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ The library provides a powerful and flexible implementation of the [self-organiz
1010

1111
## Introduction
1212

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.
1414

1515
### Self-organizing techniques
1616

@@ -19,6 +19,7 @@ A *self-organizing list* (aka *SoList*) is a list that reorders its elements bas
1919
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.
2020

2121
Pseudocode:
22+
2223
```
2324
init: count(i) = 0 for each item i
2425
At t-th item selection:
@@ -32,6 +33,7 @@ At t-th item selection:
3233
This technique moves the node which is accessed to the head of the list.
3334

3435
Pseudocode:
36+
3537
```
3638
At the t-th item selection:
3739
if item i is selected:
@@ -40,9 +42,10 @@ At the t-th item selection:
4042

4143
#### Transpose
4244

43-
This technique involves swapping an accessed node with its predecessor.
45+
This technique involves swapping an accessed node with its predecessor.
4446

4547
Pseudocode:
48+
4649
```
4750
At the t-th item selection:
4851
if item i is selected:
@@ -51,41 +54,45 @@ At the t-th item selection:
5154
```
5255

5356
### Rearrange upon creation
57+
5458
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.
5559

5660
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.
5761

5862
Methods which perform rearrange of the list:
63+
5964
- Rearrange upon search: `at()`, `find()`, `findIndex()`, `findLast()`, `findLastIndex()`, `includes()`, `indexOf()` and `lastIndexOf()`.
6065
- Rearrange upon creation: `constructor` (initialization from an iterable), `insert()`, `push()` and `unshift()`.
6166

6267
## Installation
68+
6369
```
6470
npm install solists
6571
```
6672

6773
## Example
74+
6875
```javascript
6976
const { FrequencyCountSoList, MoveToFrontSoList, TransposeSoList } = require("solists");
7077

7178
/** Examples of SoList without rearrange upon creation **/
7279

7380
// Example of SoList with Frequency Count heuristic
74-
const fcList1 = new FrequencyCountSoList(false,[1,2,3,4,5]);
81+
const fcList1 = new FrequencyCountSoList(false, [1, 2, 3, 4, 5]);
7582
console.log(fcList1.toString()); // 1,2,3,4,5
7683
fcList1.includes(2);
7784
fcList1.includes(4);
7885
console.log(fcList1.toString()); // 2,4,1,3,5
7986

8087
// Example of SoList with Move to Front heuristic
81-
const mtfList1 = new MoveToFrontSoList(false,[1,2,3,4,5]);
88+
const mtfList1 = new MoveToFrontSoList(false, [1, 2, 3, 4, 5]);
8289
console.log(mtfList1.toString()); // 1,2,3,4,5
8390
mtfList1.includes(2);
8491
mtfList1.includes(4);
8592
console.log(mtfList1.toString()); // 4,2,1,3,5
8693

8794
// Example of SoList with Transpose heuristic
88-
const tList1 = new TransposeSoList(false,[1,2,3,4,5]);
95+
const tList1 = new TransposeSoList(false, [1, 2, 3, 4, 5]);
8996
console.log(tList1.toString()); // 1,2,3,4,5
9097
tList1.includes(2);
9198
tList1.includes(4);
@@ -94,81 +101,83 @@ console.log(tList1.toString()); // 2,1,4,3,5
94101
/** Examples of SoList with rearrange upon creation **/
95102

96103
// Example of SoList with Frequency Count heuristic
97-
const fcList2 = new FrequencyCountSoList(true,[1,2,3,4,5]);
104+
const fcList2 = new FrequencyCountSoList(true, [1, 2, 3, 4, 5]);
98105
console.log(fcList2.toString()); // 1,2,3,4,5
99106
fcList2.includes(2);
100107
fcList2.includes(4);
101108
console.log(fcList2.toString()); // 2,4,1,3,5
102109

103110
// Example of SoList with Move to Front heuristic
104-
const mtfList2 = new MoveToFrontSoList(true,[1,2,3,4,5]);
111+
const mtfList2 = new MoveToFrontSoList(true, [1, 2, 3, 4, 5]);
105112
console.log(mtfList2.toString()); // 5,4,3,2,1
106113
mtfList2.includes(2);
107114
mtfList2.includes(4);
108115
console.log(mtfList2.toString()); // 4,2,5,3,1
109116

110117
// Example of SoList with Transpose heuristic
111-
const tList2 = new TransposeSoList(true,[1,2,3,4,5]);
118+
const tList2 = new TransposeSoList(true, [1, 2, 3, 4, 5]);
112119
console.log(tList2.toString()); // 2,3,4,5,1
113120
tList2.includes(2);
114121
tList2.includes(4);
115122
console.log(tList2.toString()); // 2,4,3,5,1
116-
117123
```
124+
118125
## Methods and properties
119126

120127
List of properties of SoList:
121128

122-
| Name | Description |
123-
| ------------- | ------------- |
124-
|`length`|Represents the number of elements in that SoList|
129+
| Name | Description |
130+
| -------- | ------------------------------------------------ |
131+
| `length` | Represents the number of elements in that SoList |
125132

126133
List of methods of SoList:
127134

128-
| Name | Description |
129-
| ------------- | ------------- |
130-
|`solist[Symbol.iterator]()`|Returns an iterator that yields the value of each index in the SoList|
131-
|`at()`|Returns the value at a given index|
132-
|`concat()`|Returns a new SoList consisting of merging the existing SoList with given iterable inputs|
133-
|`constructor`|Creates a new empty SoList instance or from a given iterable|
134-
|`copyWithin()`|Shallow copies part of a SoList to another location in the same SoList and returns it|
135-
|`entries()`|Returns a SoList iterator object of key/value pairs|
136-
|`every()`|Checks if every element in a SoList satisfies a predicate function|
137-
|`fill()`|Changes all elements in a SoList to a static value|
138-
|`filter()`|Creates a new SoList with every element in a SoList that satisfies a predicate function|
139-
|`find()`|Returns the value of the first element in a SoList that satisfies a predicate function|
140-
|`findIndex()`|Returns the index of the first element in a SoList that satisfies a predicate function|
141-
|`findLast()`|Returns the value of the last element in a SoList that satisfies a predicate function|
142-
|`findLastIndex()`|Returns the index of the last element in a SoList that satisfies a predicate function|
143-
|`flat()`|Creates a new SoList with all sub-SoList elements concatenated into it recursively up to the specified depth|
144-
|`forEach()`|Executes a provided function once for each SoList element|
145-
|`includes()`|Determines whether a SoList includes a certain value among its entries|
146-
|`indexOf()`|Returns the first index at which a given element can be found in a SoList|
147-
|`insert()`|Adds an element into a specific index of a SoList|
148-
|`isEmpty()`|Checks if the SoList does not contain any elements|
149-
|`isEqual()`|Checks if the SoList is equal to a given iterable|
150-
|`join()`|Joins all elements of SoList into a string separated by commas or a specified separator string|
151-
|`keys()`|Returns a SoList iterator object of keys|
152-
|`lastIndexOf()`|Returns the last index at which a given element can be found in a SoList|
153-
|`map()`|Creates a new SoList populated with the results of calling a provided function on every element of a SoList|
154-
|`pop()`|Removes the last element from a SoList and returns that element|
155-
|`push()`|Adds one or more elements to the end of a SoList and returns the new length of the SoList|
156-
|`reduce()`|Reduces the values of a SoList to a single value (going left-to-right)|
157-
|`reduceRight()`|Reduces the values of a SoList to a single value (going right-to-left)|
158-
|`remove()`|Removes the element at a specific index from a SoList|
159-
|`reverse()`|Reverses the order of the elements in a SoList|
160-
|`shift()`|removes the first element from a SoList and returns that removed element|
161-
|`slice()`|Returns a shallow copy of a portion of a SoList into a new SoList selected by positions|
162-
|`some()`|Checks if any of the elements in a SoList satisfy a predicate function|
163-
|`sort()`|Sorts the elements of a SoList and returns the reference to the same SoList, now sorted|
164-
|`splice()`|Changes the contents of a SoList by removing or replacing existing elements and/or adding new elements|
165-
|`toLocaleString()`|Returns a string representing the elements of the SoList using their `toLocaleString` methods|
166-
|`toString()`|Returns a string representing the specified SoList and its elements|
167-
|`unshift()`|Adds one or more elements to the beginning of a SoList and returns the new length of the SoList|
168-
|`values()`|Returns a SoList iterator object of values|
135+
| Name | Description |
136+
| --------------------------- | ------------------------------------------------------------------------------------------------------------ |
137+
| `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 |
169176

170177
## SoList vs JS-Array
178+
171179
Although SoList implements most of the methods of JS-Array (with identical behavior), there are several differences and limitations:
180+
172181
- Unlike JS-Array, SoList does not support empty items (for example `[1,,3]`).
173182
- Currently, the `every()`, `filter()`, `find()`, `findIndex()`, `findLast()`, `findLastIndex()`, `flatMap()` and `some()` don't support the `thisArg` argument.
174183
- Unsupported JS-Array methods: `group()` and `groupToMap()`.

0 commit comments

Comments
 (0)