solists 0.3.0 → 1.0.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.
@@ -1,6 +1,5 @@
1
- import { DoublyLinkedList } from './DoublyLinkedList';
2
- import { Node } from './Node';
3
- export declare class FrequencyCountSoList extends DoublyLinkedList {
4
- constructor(...args: any);
5
- protected _rearrange(node: Node): number;
1
+ import { DoublyLinkedList } from "./DoublyLinkedList";
2
+ import { Node } from "./Node";
3
+ export declare class FrequencyCountSoList<T> extends DoublyLinkedList<T> {
4
+ protected _rearrange(node: Node<T>): number;
6
5
  }
@@ -3,14 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FrequencyCountSoList = void 0;
4
4
  const DoublyLinkedList_1 = require("./DoublyLinkedList");
5
5
  class FrequencyCountSoList extends DoublyLinkedList_1.DoublyLinkedList {
6
- constructor(...args) {
7
- super(...args);
8
- }
9
6
  _rearrange(node) {
10
7
  let prev = node.prev;
11
8
  let next = node.next;
12
9
  if (prev !== null && prev.count < node.count) {
13
- while (!(node.isEqual(this.head))) {
10
+ while (!node.isEqual(this._head)) {
14
11
  if (prev !== null && prev.count < node.count) {
15
12
  this._remove(node);
16
13
  this._insertBefore(prev, node);
@@ -22,7 +19,7 @@ class FrequencyCountSoList extends DoublyLinkedList_1.DoublyLinkedList {
22
19
  }
23
20
  }
24
21
  else if (next !== null && next.count > node.count) {
25
- while (!(node.isEqual(this.tail))) {
22
+ while (!node.isEqual(this._tail)) {
26
23
  if (next !== null && next.count > node.count) {
27
24
  this._remove(node);
28
25
  this._insertAfter(next, node);
@@ -0,0 +1,10 @@
1
+ import { DoublyLinkedList, SoListOptions } from "./DoublyLinkedList";
2
+ import { Node } from "./Node";
3
+ export interface KInARowOptions extends SoListOptions {
4
+ k?: number;
5
+ }
6
+ export declare class KInARowSoList<T> extends DoublyLinkedList<T, KInARowOptions> {
7
+ protected _consecutiveCount: number;
8
+ protected _lastAccessedNode: Node<T> | null;
9
+ protected _rearrange(node: Node<T>): number;
10
+ }
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KInARowSoList = void 0;
4
+ const DoublyLinkedList_1 = require("./DoublyLinkedList");
5
+ class KInARowSoList extends DoublyLinkedList_1.DoublyLinkedList {
6
+ constructor() {
7
+ super(...arguments);
8
+ this._consecutiveCount = 0;
9
+ this._lastAccessedNode = null;
10
+ }
11
+ _rearrange(node) {
12
+ var _a;
13
+ const k = (_a = this._options.k) !== null && _a !== void 0 ? _a : 2;
14
+ if (this._lastAccessedNode !== null && node.isEqual(this._lastAccessedNode)) {
15
+ this._consecutiveCount += 1;
16
+ }
17
+ else {
18
+ this._consecutiveCount = 1;
19
+ this._lastAccessedNode = node;
20
+ }
21
+ if (this._consecutiveCount >= k && !node.isEqual(this._head)) {
22
+ this._remove(node);
23
+ this._insertBefore(this._head, node);
24
+ this._consecutiveCount = 0;
25
+ this._lastAccessedNode = null;
26
+ }
27
+ return this._getIndexByNode(node);
28
+ }
29
+ }
30
+ exports.KInARowSoList = KInARowSoList;
@@ -0,0 +1,8 @@
1
+ import { DoublyLinkedList, SoListOptions } from "./DoublyLinkedList";
2
+ import { Node } from "./Node";
3
+ export interface MoveAheadKOptions extends SoListOptions {
4
+ k?: number;
5
+ }
6
+ export declare class MoveAheadKSoList<T> extends DoublyLinkedList<T, MoveAheadKOptions> {
7
+ protected _rearrange(node: Node<T>): number;
8
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MoveAheadKSoList = void 0;
4
+ const DoublyLinkedList_1 = require("./DoublyLinkedList");
5
+ class MoveAheadKSoList extends DoublyLinkedList_1.DoublyLinkedList {
6
+ _rearrange(node) {
7
+ var _a;
8
+ const k = (_a = this._options.k) !== null && _a !== void 0 ? _a : 1;
9
+ if (!node.isEqual(this._head)) {
10
+ let target = node;
11
+ for (let i = 0; i < k && target.prev !== null; i++) {
12
+ target = target.prev;
13
+ }
14
+ if (!target.isEqual(node)) {
15
+ this._remove(node);
16
+ this._insertBefore(target, node);
17
+ }
18
+ }
19
+ return this._getIndexByNode(node);
20
+ }
21
+ }
22
+ exports.MoveAheadKSoList = MoveAheadKSoList;
@@ -1,6 +1,5 @@
1
- import { DoublyLinkedList } from './DoublyLinkedList';
2
- import { Node } from './Node';
3
- export declare class MoveToFrontSoList extends DoublyLinkedList {
4
- constructor(...args: any);
5
- protected _rearrange(node: Node): number;
1
+ import { DoublyLinkedList } from "./DoublyLinkedList";
2
+ import { Node } from "./Node";
3
+ export declare class MoveToFrontSoList<T> extends DoublyLinkedList<T> {
4
+ protected _rearrange(node: Node<T>): number;
6
5
  }
@@ -3,14 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MoveToFrontSoList = void 0;
4
4
  const DoublyLinkedList_1 = require("./DoublyLinkedList");
5
5
  class MoveToFrontSoList extends DoublyLinkedList_1.DoublyLinkedList {
6
- constructor(...args) {
7
- super(...args);
8
- }
9
6
  _rearrange(node) {
10
- if (!(node.isEqual(this.head))) {
11
- if (this.head !== null) {
7
+ if (!node.isEqual(this._head)) {
8
+ if (this._head !== null) {
12
9
  this._remove(node);
13
- this._insertBefore(this.head, node);
10
+ this._insertBefore(this._head, node);
14
11
  }
15
12
  }
16
13
  return this._getIndexByNode(node);
package/dist/Node.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- export declare class Node {
2
- value: unknown;
3
- next: Node | null;
4
- prev: Node | null;
1
+ export declare class Node<T> {
2
+ value: T;
3
+ next: Node<T> | null;
4
+ prev: Node<T> | null;
5
5
  count: number;
6
- constructor(value: unknown, next?: null, prev?: null);
7
- isEqual(other: Node | null): boolean;
6
+ constructor(value: T, next?: Node<T> | null, prev?: Node<T> | null);
7
+ isEqual(other: Node<T> | null): boolean;
8
8
  }
@@ -1,6 +1,5 @@
1
- import { DoublyLinkedList } from './DoublyLinkedList';
2
- import { Node } from './Node';
3
- export declare class TransposeSoList extends DoublyLinkedList {
4
- constructor(...args: any);
5
- protected _rearrange(node: Node): number;
1
+ import { DoublyLinkedList } from "./DoublyLinkedList";
2
+ import { Node } from "./Node";
3
+ export declare class TransposeSoList<T> extends DoublyLinkedList<T> {
4
+ protected _rearrange(node: Node<T>): number;
6
5
  }
@@ -3,11 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TransposeSoList = void 0;
4
4
  const DoublyLinkedList_1 = require("./DoublyLinkedList");
5
5
  class TransposeSoList extends DoublyLinkedList_1.DoublyLinkedList {
6
- constructor(...args) {
7
- super(...args);
8
- }
9
6
  _rearrange(node) {
10
- if (!(node.isEqual(this.head))) {
7
+ if (!node.isEqual(this._head)) {
11
8
  const prev = node.prev;
12
9
  if (prev !== null) {
13
10
  this._remove(node);
package/dist/index.d.ts CHANGED
@@ -1,4 +1,7 @@
1
- import { FrequencyCountSoList } from './FrequencyCountSoList';
2
- import { MoveToFrontSoList } from './MoveToFrontSoList';
3
- import { TransposeSoList } from './TransposeSoList';
4
- export { FrequencyCountSoList, MoveToFrontSoList, TransposeSoList };
1
+ import { KInARowOptions, KInARowSoList } from "./KInARowSoList";
2
+ import { MoveAheadKOptions, MoveAheadKSoList } from "./MoveAheadKSoList";
3
+ import { FrequencyCountSoList } from "./FrequencyCountSoList";
4
+ import { MoveToFrontSoList } from "./MoveToFrontSoList";
5
+ import { SoListOptions } from "./DoublyLinkedList";
6
+ import { TransposeSoList } from "./TransposeSoList";
7
+ export { FrequencyCountSoList, KInARowOptions, KInARowSoList, MoveAheadKOptions, MoveAheadKSoList, MoveToFrontSoList, SoListOptions, TransposeSoList, };
package/dist/index.js CHANGED
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TransposeSoList = exports.MoveToFrontSoList = exports.FrequencyCountSoList = void 0;
3
+ exports.TransposeSoList = exports.MoveToFrontSoList = exports.MoveAheadKSoList = exports.KInARowSoList = exports.FrequencyCountSoList = void 0;
4
+ const KInARowSoList_1 = require("./KInARowSoList");
5
+ Object.defineProperty(exports, "KInARowSoList", { enumerable: true, get: function () { return KInARowSoList_1.KInARowSoList; } });
6
+ const MoveAheadKSoList_1 = require("./MoveAheadKSoList");
7
+ Object.defineProperty(exports, "MoveAheadKSoList", { enumerable: true, get: function () { return MoveAheadKSoList_1.MoveAheadKSoList; } });
4
8
  const FrequencyCountSoList_1 = require("./FrequencyCountSoList");
5
9
  Object.defineProperty(exports, "FrequencyCountSoList", { enumerable: true, get: function () { return FrequencyCountSoList_1.FrequencyCountSoList; } });
6
10
  const MoveToFrontSoList_1 = require("./MoveToFrontSoList");
package/package.json CHANGED
@@ -1,14 +1,17 @@
1
1
  {
2
2
  "name": "solists",
3
- "version": "0.3.0",
4
- "description": "Implementation of self-organizing lists",
3
+ "version": "1.0.0",
4
+ "description": "Self-organizing lists with native Array methods",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "scripts": {
8
8
  "build": "npm run clean && tsc",
9
9
  "clean": "rimraf ./dist",
10
- "coverage": "nyc --reporter=html ts-mocha tests/test.ts",
11
- "lint": "eslint ./src ./tests",
10
+ "coverage": "nyc --reporter=html --reporter=lcov ts-mocha tests/test.ts",
11
+ "format": "prettier --check .",
12
+ "format:fix": "prettier --write .",
13
+ "lint": "eslint .",
14
+ "lint:fix": "eslint --fix .",
12
15
  "test": "ts-mocha tests/test.ts"
13
16
  },
14
17
  "repository": {
@@ -16,7 +19,10 @@
16
19
  "url": "git+https://github.com/emmanuel-ferdman/solists.git"
17
20
  },
18
21
  "keywords": [
22
+ "array",
19
23
  "data-structure",
24
+ "linked-list",
25
+ "list",
20
26
  "self-organizing-list"
21
27
  ],
22
28
  "author": "Emmanuel Ferdman",
@@ -26,14 +32,17 @@
26
32
  },
27
33
  "homepage": "https://github.com/emmanuel-ferdman/solists#readme",
28
34
  "devDependencies": {
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",
33
- "nyc": "^15.1.0",
34
- "ts-mocha": "^10.0.0",
35
+ "@eslint/js": "^10.0.1",
36
+ "@typescript-eslint/eslint-plugin": "^8.50.0",
37
+ "@typescript-eslint/parser": "^8.50.0",
38
+ "eslint": "^10.0.2",
39
+ "mocha": "^11.7.5",
40
+ "nyc": "^18.0.0",
41
+ "prettier": "^3.6.2",
42
+ "ts-mocha": "^11.1.0",
35
43
  "ts-node": "^10.9.2",
36
- "typescript": "^5.4.3"
44
+ "typescript": "^5.4.3",
45
+ "typescript-eslint": "^8.56.1"
37
46
  },
38
47
  "files": [
39
48
  "dist"