Skip to content

Commit

Permalink
Small cleanups and setup build script
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiuandrei committed Jul 25, 2023
1 parent 84b7f26 commit 88fbc95
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 190 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ key-value pairs.
### set

```typescript
set(keys: K[], value: V): void
set(keys: K[], value: V): this
```

Inserts or updates a key-value pair in the trie.
Expand Down
2 changes: 1 addition & 1 deletion fqueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class FQueue<T> {
}

*entries(): IterableIterator<[T, T]> {
for (const value of this[Symbol.iterator]()) {
for (const value of this) {
yield [value, value];
}
}
Expand Down
4 changes: 2 additions & 2 deletions lfu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class LFU<K, V> {
}

*[Symbol.iterator](): IterableIterator<[K, V]> {
for (const key of this.#queue[Symbol.iterator]()) {
for (const key of this.#queue) {
yield [key, this.#store.get(key)!];
}
}
Expand All @@ -73,7 +73,7 @@ class LFU<K, V> {
}

*values(): IterableIterator<V> {
for (const key of this.#queue[Symbol.iterator]()) {
for (const key of this.#queue) {
yield this.#store.get(key)!;
}
}
Expand Down
2 changes: 1 addition & 1 deletion list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class LinkedList<T> {
}

*entities(): IterableIterator<[T, T]> {
for (const value of this[Symbol.iterator]()) {
for (const value of this) {
yield [value, value];
}
}
Expand Down
4 changes: 2 additions & 2 deletions queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Queue<T> {
}

*[Symbol.iterator](): IterableIterator<T> {
for (const [value] of this.#store[Symbol.iterator]()) {
for (const [value] of this.#store) {
yield value;
}
}
Expand All @@ -72,7 +72,7 @@ class Queue<T> {
}

*entries(): IterableIterator<[T, T]> {
for (const value of this[Symbol.iterator]()) {
for (const value of this) {
yield [value, value];
}
}
Expand Down
70 changes: 41 additions & 29 deletions scripts/build_npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,47 @@ import { build, emptyDir } from "https://deno.land/x/dnt@0.31.0/mod.ts";
await emptyDir("./npm");

await build({
entryPoints: ["./mod.ts"],
outDir: "./npm",
shims: {
// see JS docs for overview and more options
deno: {
test: "dev",
},
},
compilerOptions: {
lib: ["es2021", "dom"],
},
package: {
// package.json properties
name: "@denox/fnv1a",
version: Deno.args[0],
description: "FNV-1a non-cryptographic hash function.",
license: "MIT",
keywords: ["fnv1a", "hash", "hashing"],
repository: {
type: "git",
url: "git+https://github.com/claudiuandrei/fnv1a.git",
},
bugs: {
url: "https://github.com/claudiuandrei/fnv1a/issues",
},
engines: {
node: ">=11.0.0",
},
},
entryPoints: ["./mod.ts"],
outDir: "./npm",
shims: {
// see JS docs for overview and more options
deno: {
test: "dev",
},
},
compilerOptions: {
lib: ["es2021", "dom"],
},
package: {
// package.json properties
name: "@denox/cube",
version: Deno.args[0],
description: "Library of building blocks for TypeScript",
license: "MIT",
keywords: [
"heap",
"trie",
"linked list",
"stack",
"queue",
"buffer",
"frequency queue",
"LFU",
"LRU",
"pubsub",
"channel",
],
repository: {
type: "git",
url: "git+https://github.com/claudiuandrei/cube.git",
},
bugs: {
url: "https://github.com/claudiuandrei/cube/issues",
},
engines: {
node: ">=11.0.0",
},
},
});

// post build steps
Expand Down
141 changes: 0 additions & 141 deletions scripts/sl_list.ts

This file was deleted.

2 changes: 1 addition & 1 deletion stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Stack<T> {
}

*entries(): IterableIterator<[T, T]> {
for (const value of this[Symbol.iterator]()) {
for (const value of this) {
yield [value, value];
}
}
Expand Down
9 changes: 6 additions & 3 deletions trie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class Trie<K, V> {
return node;
}

set(keys: K[], value: V): void {
set(keys: K[], value: V): this {
// Start at the head
let node = this.#head;

Expand All @@ -137,6 +137,9 @@ class Trie<K, V> {

// Set the value on the value
node[1] = value;

// Chain
return this;
}

get(keys: K[]): V | undefined {
Expand Down Expand Up @@ -233,13 +236,13 @@ class Trie<K, V> {
}

*keys(): IterableIterator<K[]> {
for (const [key] of this[Symbol.iterator]()) {
for (const [key] of this) {
yield key;
}
}

*values(): IterableIterator<V> {
for (const [, value] of this[Symbol.iterator]()) {
for (const [, value] of this) {
yield value;
}
}
Expand Down
13 changes: 4 additions & 9 deletions trie_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,15 @@ Deno.test("Trie Insertion - insert into empty trie", () => {

Deno.test("Trie Insertion - insert multiple values", () => {
const trie = new Trie<string, number>();
trie.set(["a"], 1);
trie.set(["b"], 2);
trie.set(["a"], 1).set(["b"], 2);
assertEquals(trie.size, 2);
assertEquals(trie.get(["a"]), 1);
assertEquals(trie.get(["b"]), 2);
});

Deno.test("Trie Insertion - insert duplicate keys with different values", () => {
const trie = new Trie<string, number>();
trie.set(["a"], 1);
trie.set(["a"], 2);
trie.set(["a"], 1).set(["a"], 2);
assertEquals(trie.size, 1);
assertEquals(trie.get(["a"]), 2);
});
Expand Down Expand Up @@ -147,8 +145,7 @@ Deno.test("Trie Match - match with non-existing prefix", () => {

Deno.test("Trie Match - match with existing prefix", () => {
const trie = new Trie<string, number>();
trie.set(["a"], 1);
trie.set(["a", "b"], 2);
trie.set(["a"], 1).set(["a", "b"], 2);
const entries = [...trie.match(["a", "b"])];
assertEquals(entries.length, 2);
assertEquals(entries[0], [["a"], 1]);
Expand All @@ -157,9 +154,7 @@ Deno.test("Trie Match - match with existing prefix", () => {

Deno.test("Trie Match - match with common prefix", () => {
const trie = new Trie<string, number>();
trie.set(["a", "b"], 1);
trie.set(["a", "b", "c"], 2);
trie.set(["a", "b", "c", "d"], 3);
trie.set(["a", "b"], 1).set(["a", "b", "c"], 2).set(["a", "b", "c", "d"], 3);
const entries = [...trie.match(["a", "b", "c"])];
assertEquals(entries.length, 2);
assertEquals(entries[0], [["a", "b"], 1]);
Expand Down

0 comments on commit 88fbc95

Please sign in to comment.