@tanstack/db-ivm 0.1.26 → 0.2.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/README.md +5 -6
- package/dist/cjs/hashing/hash.cjs +58 -3
- package/dist/cjs/hashing/hash.cjs.map +1 -1
- package/dist/cjs/hashing/hash.d.cts +9 -0
- package/dist/cjs/hashing/murmur.cjs +26 -15
- package/dist/cjs/hashing/murmur.cjs.map +1 -1
- package/dist/cjs/hashing/murmur.d.cts +2 -0
- package/dist/cjs/index.cjs +0 -26
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/indexes.cjs +52 -16
- package/dist/cjs/indexes.cjs.map +1 -1
- package/dist/cjs/indexes.d.cts +4 -1
- package/dist/cjs/operators/groupBy.cjs +33 -36
- package/dist/cjs/operators/groupBy.cjs.map +1 -1
- package/dist/cjs/operators/groupBy.d.cts +1 -5
- package/dist/cjs/operators/groupedTopKWithFractionalIndex.cjs +3 -9
- package/dist/cjs/operators/groupedTopKWithFractionalIndex.cjs.map +1 -1
- package/dist/cjs/operators/groupedTopKWithFractionalIndex.d.cts +1 -15
- package/dist/cjs/operators/index.d.cts +0 -6
- package/dist/cjs/operators/join.cjs +0 -20
- package/dist/cjs/operators/join.cjs.map +1 -1
- package/dist/cjs/operators/join.d.cts +0 -40
- package/dist/cjs/operators/orderBy.cjs +2 -77
- package/dist/cjs/operators/orderBy.cjs.map +1 -1
- package/dist/cjs/operators/orderBy.d.cts +2 -31
- package/dist/cjs/operators/reduce.cjs +36 -5
- package/dist/cjs/operators/reduce.cjs.map +1 -1
- package/dist/cjs/operators/reduce.d.cts +11 -2
- package/dist/cjs/operators/topKArray.cjs +9 -0
- package/dist/cjs/operators/topKArray.cjs.map +1 -1
- package/dist/cjs/operators/topKArray.d.cts +6 -0
- package/dist/cjs/operators/topKState.cjs +3 -0
- package/dist/cjs/operators/topKState.cjs.map +1 -1
- package/dist/cjs/operators/topKState.d.cts +1 -0
- package/dist/cjs/operators/topKWithFractionalIndex.cjs +5 -9
- package/dist/cjs/operators/topKWithFractionalIndex.cjs.map +1 -1
- package/dist/cjs/operators/topKWithFractionalIndex.d.cts +7 -12
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.cts +0 -7
- package/dist/esm/hashing/hash.d.ts +9 -0
- package/dist/esm/hashing/hash.js +60 -5
- package/dist/esm/hashing/hash.js.map +1 -1
- package/dist/esm/hashing/murmur.d.ts +2 -0
- package/dist/esm/hashing/murmur.js +26 -15
- package/dist/esm/hashing/murmur.js.map +1 -1
- package/dist/esm/index.js +3 -29
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/indexes.d.ts +4 -1
- package/dist/esm/indexes.js +52 -16
- package/dist/esm/indexes.js.map +1 -1
- package/dist/esm/operators/groupBy.d.ts +1 -5
- package/dist/esm/operators/groupBy.js +33 -36
- package/dist/esm/operators/groupBy.js.map +1 -1
- package/dist/esm/operators/groupedTopKWithFractionalIndex.d.ts +1 -6
- package/dist/esm/operators/groupedTopKWithFractionalIndex.js +3 -9
- package/dist/esm/operators/groupedTopKWithFractionalIndex.js.map +1 -1
- package/dist/esm/operators/index.d.ts +0 -6
- package/dist/esm/operators/join.d.ts +0 -25
- package/dist/esm/operators/join.js +1 -21
- package/dist/esm/operators/join.js.map +1 -1
- package/dist/esm/operators/orderBy.d.ts +2 -22
- package/dist/esm/operators/orderBy.js +3 -78
- package/dist/esm/operators/orderBy.js.map +1 -1
- package/dist/esm/operators/reduce.d.ts +11 -2
- package/dist/esm/operators/reduce.js +36 -5
- package/dist/esm/operators/reduce.js.map +1 -1
- package/dist/esm/operators/topKArray.d.ts +6 -0
- package/dist/esm/operators/topKArray.js +9 -0
- package/dist/esm/operators/topKArray.js.map +1 -1
- package/dist/esm/operators/topKState.d.ts +1 -0
- package/dist/esm/operators/topKState.js +3 -0
- package/dist/esm/operators/topKState.js.map +1 -1
- package/dist/esm/operators/topKWithFractionalIndex.d.ts +7 -3
- package/dist/esm/operators/topKWithFractionalIndex.js +6 -10
- package/dist/esm/operators/topKWithFractionalIndex.js.map +1 -1
- package/dist/esm/utils.d.ts +0 -7
- package/dist/esm/utils.js.map +1 -1
- package/package.json +2 -4
- package/src/hashing/hash.ts +87 -5
- package/src/hashing/murmur.ts +31 -17
- package/src/indexes.ts +65 -16
- package/src/operators/groupBy.ts +48 -58
- package/src/operators/groupedTopKWithFractionalIndex.ts +4 -15
- package/src/operators/index.ts +0 -6
- package/src/operators/join.ts +0 -90
- package/src/operators/orderBy.ts +6 -141
- package/src/operators/reduce.ts +60 -3
- package/src/operators/topKArray.ts +15 -0
- package/src/operators/topKState.ts +7 -0
- package/src/operators/topKWithFractionalIndex.ts +15 -16
- package/src/utils.ts +0 -30
- package/dist/cjs/operators/count.cjs +0 -35
- package/dist/cjs/operators/count.cjs.map +0 -1
- package/dist/cjs/operators/count.d.cts +0 -19
- package/dist/cjs/operators/debug.cjs +0 -39
- package/dist/cjs/operators/debug.cjs.map +0 -1
- package/dist/cjs/operators/debug.d.cts +0 -16
- package/dist/cjs/operators/filterBy.cjs +0 -19
- package/dist/cjs/operators/filterBy.cjs.map +0 -1
- package/dist/cjs/operators/filterBy.d.cts +0 -9
- package/dist/cjs/operators/keying.cjs +0 -16
- package/dist/cjs/operators/keying.cjs.map +0 -1
- package/dist/cjs/operators/keying.d.cts +0 -22
- package/dist/cjs/operators/negate.cjs +0 -27
- package/dist/cjs/operators/negate.cjs.map +0 -1
- package/dist/cjs/operators/negate.d.cts +0 -13
- package/dist/cjs/operators/topK.cjs +0 -39
- package/dist/cjs/operators/topK.cjs.map +0 -1
- package/dist/cjs/operators/topK.d.cts +0 -34
- package/dist/cjs/operators/topKWithFractionalIndexBTree.d.cts +0 -43
- package/dist/esm/operators/count.d.ts +0 -13
- package/dist/esm/operators/count.js +0 -35
- package/dist/esm/operators/count.js.map +0 -1
- package/dist/esm/operators/debug.d.ts +0 -16
- package/dist/esm/operators/debug.js +0 -39
- package/dist/esm/operators/debug.js.map +0 -1
- package/dist/esm/operators/filterBy.d.ts +0 -9
- package/dist/esm/operators/filterBy.js +0 -19
- package/dist/esm/operators/filterBy.js.map +0 -1
- package/dist/esm/operators/keying.d.ts +0 -19
- package/dist/esm/operators/keying.js +0 -16
- package/dist/esm/operators/keying.js.map +0 -1
- package/dist/esm/operators/negate.d.ts +0 -13
- package/dist/esm/operators/negate.js +0 -27
- package/dist/esm/operators/negate.js.map +0 -1
- package/dist/esm/operators/topK.d.ts +0 -31
- package/dist/esm/operators/topK.js +0 -39
- package/dist/esm/operators/topK.js.map +0 -1
- package/dist/esm/operators/topKWithFractionalIndexBTree.d.ts +0 -28
- package/src/operators/count.ts +0 -51
- package/src/operators/debug.ts +0 -57
- package/src/operators/filterBy.ts +0 -30
- package/src/operators/keying.ts +0 -34
- package/src/operators/negate.ts +0 -32
- package/src/operators/topK.ts +0 -91
- package/src/operators/topKWithFractionalIndexBTree.ts +0 -297
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"filterBy.cjs","sources":["../../../src/operators/filterBy.ts"],"sourcesContent":["import { map } from './map.js'\nimport { innerJoin } from './join.js'\nimport { consolidate } from './consolidate.js'\nimport type { IStreamBuilder, KeyValue, PipedOperator } from '../types.js'\n\n/**\n * Filters the elements of a keyed stream, by keys of another stream.\n * This allows you to build pipelies where you have multiple outputs that are related,\n * such as a streams of issues and comments for a project.\n *\n * @param other - The other stream to filter by, which must have the same key type as the input stream\n */\nexport function filterBy<\n K,\n V1 extends (T extends KeyValue<infer _KT, infer VT> ? VT : never),\n T,\n>(\n other: IStreamBuilder<KeyValue<K, unknown>>,\n): PipedOperator<T, KeyValue<K, V1>> {\n return (stream: IStreamBuilder<T>): IStreamBuilder<KeyValue<K, V1>> => {\n const otherKeys = other.pipe(\n map(([key, _]) => [key, null] as KeyValue<K, null>),\n )\n return stream.pipe(\n innerJoin(otherKeys),\n map(([key, [value, _]]) => [key, value] as KeyValue<K, V1>),\n consolidate(),\n )\n }\n}\n"],"names":["map","innerJoin","consolidate"],"mappings":";;;;;AAYO,SAAS,SAKd,OACmC;AACnC,SAAO,CAAC,WAA+D;AACrE,UAAM,YAAY,MAAM;AAAA,MACtBA,IAAAA,IAAI,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI,CAAsB;AAAA,IAAA;AAEpD,WAAO,OAAO;AAAA,MACZC,KAAAA,UAAU,SAAS;AAAA,MACnBD,QAAI,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,KAAK,CAAoB;AAAA,MAC1DE,YAAAA,YAAA;AAAA,IAAY;AAAA,EAEhB;AACF;;"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { IStreamBuilder, KeyValue, PipedOperator } from "../types.cjs";
|
|
2
|
-
/**
|
|
3
|
-
* Filters the elements of a keyed stream, by keys of another stream.
|
|
4
|
-
* This allows you to build pipelies where you have multiple outputs that are related,
|
|
5
|
-
* such as a streams of issues and comments for a project.
|
|
6
|
-
*
|
|
7
|
-
* @param other - The other stream to filter by, which must have the same key type as the input stream
|
|
8
|
-
*/
|
|
9
|
-
export declare function filterBy<K, V1 extends (T extends KeyValue<infer _KT, infer VT> ? VT : never), T>(other: IStreamBuilder<KeyValue<K, unknown>>): PipedOperator<T, KeyValue<K, V1>>;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const map = require("./map.cjs");
|
|
4
|
-
function keyBy(keyFn) {
|
|
5
|
-
return map.map((value) => [keyFn(value), value]);
|
|
6
|
-
}
|
|
7
|
-
function unkey() {
|
|
8
|
-
return map.map(([_, value]) => value);
|
|
9
|
-
}
|
|
10
|
-
function rekey(keyFn) {
|
|
11
|
-
return map.map(([_, value]) => [keyFn(value), value]);
|
|
12
|
-
}
|
|
13
|
-
exports.keyBy = keyBy;
|
|
14
|
-
exports.rekey = rekey;
|
|
15
|
-
exports.unkey = unkey;
|
|
16
|
-
//# sourceMappingURL=keying.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"keying.cjs","sources":["../../../src/operators/keying.ts"],"sourcesContent":["import { map } from './map.js'\nimport type { PipedOperator } from '../types.js'\n\n/**\n * Type for a keyed value\n */\nexport type Keyed<K, V> = [K, V]\n\n/**\n * Takes an unkeyed input and returns a keyed result\n * @param keyFn - Function to generate the key for each value\n */\nexport function keyBy<T, K>(\n keyFn: (value: T) => K,\n): PipedOperator<T, Keyed<K, T>> {\n return map((value: T): Keyed<K, T> => [keyFn(value), value])\n}\n\n/**\n * Removes the key from a keyed stream\n */\nexport function unkey<K, V>(): PipedOperator<Keyed<K, V>, V> {\n return map(([_, value]: Keyed<K, V>): V => value)\n}\n\n/**\n * Takes a keyed input and rekeys it with a new key\n * @param keyFn - Function to generate the new key for each value\n */\nexport function rekey<K1, K2, V>(\n keyFn: (value: V) => K2,\n): PipedOperator<Keyed<K1, V>, Keyed<K2, V>> {\n return map(([_, value]: Keyed<K1, V>): Keyed<K2, V> => [keyFn(value), value])\n}\n"],"names":["map"],"mappings":";;;AAYO,SAAS,MACd,OAC+B;AAC/B,SAAOA,IAAAA,IAAI,CAAC,UAA0B,CAAC,MAAM,KAAK,GAAG,KAAK,CAAC;AAC7D;AAKO,SAAS,QAA6C;AAC3D,SAAOA,IAAAA,IAAI,CAAC,CAAC,GAAG,KAAK,MAAsB,KAAK;AAClD;AAMO,SAAS,MACd,OAC2C;AAC3C,SAAOA,IAAAA,IAAI,CAAC,CAAC,GAAG,KAAK,MAAkC,CAAC,MAAM,KAAK,GAAG,KAAK,CAAC;AAC9E;;;;"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { PipedOperator } from "../types.cjs";
|
|
2
|
-
/**
|
|
3
|
-
* Type for a keyed value
|
|
4
|
-
*/
|
|
5
|
-
export type Keyed<K, V> = [
|
|
6
|
-
K,
|
|
7
|
-
V
|
|
8
|
-
];
|
|
9
|
-
/**
|
|
10
|
-
* Takes an unkeyed input and returns a keyed result
|
|
11
|
-
* @param keyFn - Function to generate the key for each value
|
|
12
|
-
*/
|
|
13
|
-
export declare function keyBy<T, K>(keyFn: (value: T) => K): PipedOperator<T, Keyed<K, T>>;
|
|
14
|
-
/**
|
|
15
|
-
* Removes the key from a keyed stream
|
|
16
|
-
*/
|
|
17
|
-
export declare function unkey<K, V>(): PipedOperator<Keyed<K, V>, V>;
|
|
18
|
-
/**
|
|
19
|
-
* Takes a keyed input and rekeys it with a new key
|
|
20
|
-
* @param keyFn - Function to generate the new key for each value
|
|
21
|
-
*/
|
|
22
|
-
export declare function rekey<K1, K2, V>(keyFn: (value: V) => K2): PipedOperator<Keyed<K1, V>, Keyed<K2, V>>;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const graph = require("../graph.cjs");
|
|
4
|
-
const d2 = require("../d2.cjs");
|
|
5
|
-
class NegateOperator extends graph.LinearUnaryOperator {
|
|
6
|
-
inner(collection) {
|
|
7
|
-
return collection.negate();
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
function negate() {
|
|
11
|
-
return (stream) => {
|
|
12
|
-
const output = new d2.StreamBuilder(
|
|
13
|
-
stream.graph,
|
|
14
|
-
new graph.DifferenceStreamWriter()
|
|
15
|
-
);
|
|
16
|
-
const operator = new NegateOperator(
|
|
17
|
-
stream.graph.getNextOperatorId(),
|
|
18
|
-
stream.connectReader(),
|
|
19
|
-
output.writer
|
|
20
|
-
);
|
|
21
|
-
stream.graph.addOperator(operator);
|
|
22
|
-
return output;
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
exports.NegateOperator = NegateOperator;
|
|
26
|
-
exports.negate = negate;
|
|
27
|
-
//# sourceMappingURL=negate.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"negate.cjs","sources":["../../../src/operators/negate.ts"],"sourcesContent":["import { DifferenceStreamWriter, LinearUnaryOperator } from '../graph.js'\nimport { StreamBuilder } from '../d2.js'\nimport type { IStreamBuilder, PipedOperator } from '../types.js'\nimport type { MultiSet } from '../multiset.js'\n\n/**\n * Operator that negates the multiplicities in the input stream\n */\nexport class NegateOperator<T> extends LinearUnaryOperator<T, T> {\n inner(collection: MultiSet<T>): MultiSet<T> {\n return collection.negate()\n }\n}\n\n/**\n * Negates the multiplicities in the input stream\n */\nexport function negate<T>(): PipedOperator<T, T> {\n return (stream: IStreamBuilder<T>): IStreamBuilder<T> => {\n const output = new StreamBuilder<T>(\n stream.graph,\n new DifferenceStreamWriter<T>(),\n )\n const operator = new NegateOperator<T>(\n stream.graph.getNextOperatorId(),\n stream.connectReader(),\n output.writer,\n )\n stream.graph.addOperator(operator)\n return output\n }\n}\n"],"names":["LinearUnaryOperator","StreamBuilder","DifferenceStreamWriter"],"mappings":";;;;AAQO,MAAM,uBAA0BA,MAAAA,oBAA0B;AAAA,EAC/D,MAAM,YAAsC;AAC1C,WAAO,WAAW,OAAA;AAAA,EACpB;AACF;AAKO,SAAS,SAAiC;AAC/C,SAAO,CAAC,WAAiD;AACvD,UAAM,SAAS,IAAIC,GAAAA;AAAAA,MACjB,OAAO;AAAA,MACP,IAAIC,MAAAA,uBAAA;AAAA,IAA0B;AAEhC,UAAM,WAAW,IAAI;AAAA,MACnB,OAAO,MAAM,kBAAA;AAAA,MACb,OAAO,cAAA;AAAA,MACP,OAAO;AAAA,IAAA;AAET,WAAO,MAAM,YAAY,QAAQ;AACjC,WAAO;AAAA,EACT;AACF;;;"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { LinearUnaryOperator } from "../graph.cjs";
|
|
2
|
-
import { PipedOperator } from "../types.cjs";
|
|
3
|
-
import { MultiSet } from "../multiset.cjs";
|
|
4
|
-
/**
|
|
5
|
-
* Operator that negates the multiplicities in the input stream
|
|
6
|
-
*/
|
|
7
|
-
export declare class NegateOperator<T> extends LinearUnaryOperator<T, T> {
|
|
8
|
-
inner(collection: MultiSet<T>): MultiSet<T>;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Negates the multiplicities in the input stream
|
|
12
|
-
*/
|
|
13
|
-
export declare function negate<T>(): PipedOperator<T, T>;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const multiset = require("../multiset.cjs");
|
|
4
|
-
const reduce = require("./reduce.cjs");
|
|
5
|
-
function topK(comparator, options) {
|
|
6
|
-
const limit = options?.limit ?? Infinity;
|
|
7
|
-
const offset = options?.offset ?? 0;
|
|
8
|
-
return (stream) => {
|
|
9
|
-
const reduced = stream.pipe(
|
|
10
|
-
reduce.reduce((values) => {
|
|
11
|
-
const consolidated = new multiset.MultiSet(values).consolidate();
|
|
12
|
-
const sortedValues = consolidated.getInner().sort((a, b) => comparator(a[0], b[0]));
|
|
13
|
-
return sortedValues.slice(offset, offset + limit);
|
|
14
|
-
})
|
|
15
|
-
);
|
|
16
|
-
return reduced;
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
function topKWithIndex(comparator, options) {
|
|
20
|
-
const limit = options?.limit ?? Infinity;
|
|
21
|
-
const offset = options?.offset ?? 0;
|
|
22
|
-
return (stream) => {
|
|
23
|
-
const reduced = stream.pipe(
|
|
24
|
-
reduce.reduce((values) => {
|
|
25
|
-
const consolidated = new multiset.MultiSet(values).consolidate();
|
|
26
|
-
let i = offset;
|
|
27
|
-
const sortedValues = consolidated.getInner().sort((a, b) => comparator(a[0], b[0])).slice(offset, offset + limit).map(([value, multiplicity]) => [
|
|
28
|
-
[value, i++],
|
|
29
|
-
multiplicity
|
|
30
|
-
]);
|
|
31
|
-
return sortedValues;
|
|
32
|
-
})
|
|
33
|
-
);
|
|
34
|
-
return reduced;
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
exports.topK = topK;
|
|
38
|
-
exports.topKWithIndex = topKWithIndex;
|
|
39
|
-
//# sourceMappingURL=topK.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"topK.cjs","sources":["../../../src/operators/topK.ts"],"sourcesContent":["import { MultiSet } from '../multiset.js'\nimport { reduce } from './reduce.js'\nimport type { IStreamBuilder, KeyValue, PipedOperator } from '../types'\n\ninterface TopKOptions {\n limit?: number\n offset?: number\n}\n\n/**\n * Limits the number of results based on a comparator, with optional offset.\n * This works on a keyed stream, where the key is the first element of the tuple\n * The ordering is withing a key group, i.e. elements are sorted within a key group\n * and the limit + offset is applied to that sorted group.\n * To order the entire stream, key by the same value for all elements such as null.\n *\n * @param comparator - A function that compares two elements\n * @param options - An optional object containing limit and offset properties\n * @returns A piped operator that limits the number of results\n */\nexport function topK<\n KType extends (T extends KeyValue<infer K, infer _V> ? K : never),\n V1Type extends (T extends KeyValue<KType, infer V> ? V : never),\n T,\n>(\n comparator: (a: V1Type, b: V1Type) => number,\n options?: TopKOptions,\n): PipedOperator<T, T> {\n const limit = options?.limit ?? Infinity\n const offset = options?.offset ?? 0\n\n return (stream: IStreamBuilder<T>): IStreamBuilder<T> => {\n const reduced = stream.pipe(\n reduce((values) => {\n // `values` is a list of tuples, first element is the value, second is the multiplicity\n const consolidated = new MultiSet(values).consolidate()\n const sortedValues = consolidated\n .getInner()\n .sort((a, b) => comparator(a[0] as V1Type, b[0] as V1Type))\n return sortedValues.slice(offset, offset + limit)\n }),\n )\n return reduced as IStreamBuilder<T>\n }\n}\n\n/**\n * Limits the number of results based on a comparator, with optional offset.\n * This works on a keyed stream, where the key is the first element of the tuple\n * The ordering is withing a key group, i.e. elements are sorted within a key group\n * and the limit + offset is applied to that sorted group.\n * To order the entire stream, key by the same value for all elements such as null.\n * Adds the index of the element to the result as [key, [value, index]]\n *\n * @param comparator - A function that compares two elements\n * @param options - An optional object containing limit and offset properties\n * @returns A piped operator that orders the elements and limits the number of results\n */\nexport function topKWithIndex<\n KType extends (T extends KeyValue<infer K, infer _V> ? K : never),\n V1Type extends (T extends KeyValue<KType, infer V> ? V : never),\n T,\n>(\n comparator: (a: V1Type, b: V1Type) => number,\n options?: TopKOptions,\n): PipedOperator<T, KeyValue<KType, [V1Type, number]>> {\n const limit = options?.limit ?? Infinity\n const offset = options?.offset ?? 0\n\n return (\n stream: IStreamBuilder<T>,\n ): IStreamBuilder<KeyValue<KType, [V1Type, number]>> => {\n const reduced = stream.pipe(\n reduce<KType, V1Type, [V1Type, number], T>((values) => {\n // `values` is a list of tuples, first element is the value, second is the multiplicity\n const consolidated = new MultiSet(values).consolidate()\n let i = offset\n const sortedValues = consolidated\n .getInner()\n .sort((a, b) => comparator(a[0], b[0]))\n .slice(offset, offset + limit)\n .map(([value, multiplicity]): [[V1Type, number], number] => [\n [value, i++],\n multiplicity,\n ])\n return sortedValues\n }),\n )\n return reduced\n }\n}\n"],"names":["reduce","MultiSet"],"mappings":";;;;AAoBO,SAAS,KAKd,YACA,SACqB;AACrB,QAAM,QAAQ,SAAS,SAAS;AAChC,QAAM,SAAS,SAAS,UAAU;AAElC,SAAO,CAAC,WAAiD;AACvD,UAAM,UAAU,OAAO;AAAA,MACrBA,OAAAA,OAAO,CAAC,WAAW;AAEjB,cAAM,eAAe,IAAIC,SAAAA,SAAS,MAAM,EAAE,YAAA;AAC1C,cAAM,eAAe,aAClB,SAAA,EACA,KAAK,CAAC,GAAG,MAAM,WAAW,EAAE,CAAC,GAAa,EAAE,CAAC,CAAW,CAAC;AAC5D,eAAO,aAAa,MAAM,QAAQ,SAAS,KAAK;AAAA,MAClD,CAAC;AAAA,IAAA;AAEH,WAAO;AAAA,EACT;AACF;AAcO,SAAS,cAKd,YACA,SACqD;AACrD,QAAM,QAAQ,SAAS,SAAS;AAChC,QAAM,SAAS,SAAS,UAAU;AAElC,SAAO,CACL,WACsD;AACtD,UAAM,UAAU,OAAO;AAAA,MACrBD,OAAAA,OAA2C,CAAC,WAAW;AAErD,cAAM,eAAe,IAAIC,SAAAA,SAAS,MAAM,EAAE,YAAA;AAC1C,YAAI,IAAI;AACR,cAAM,eAAe,aAClB,SAAA,EACA,KAAK,CAAC,GAAG,MAAM,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EACrC,MAAM,QAAQ,SAAS,KAAK,EAC5B,IAAI,CAAC,CAAC,OAAO,YAAY,MAAkC;AAAA,UAC1D,CAAC,OAAO,GAAG;AAAA,UACX;AAAA,QAAA,CACD;AACH,eAAO;AAAA,MACT,CAAC;AAAA,IAAA;AAEH,WAAO;AAAA,EACT;AACF;;;"}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { KeyValue, PipedOperator } from '../types.cjs';
|
|
2
|
-
interface TopKOptions {
|
|
3
|
-
limit?: number;
|
|
4
|
-
offset?: number;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Limits the number of results based on a comparator, with optional offset.
|
|
8
|
-
* This works on a keyed stream, where the key is the first element of the tuple
|
|
9
|
-
* The ordering is withing a key group, i.e. elements are sorted within a key group
|
|
10
|
-
* and the limit + offset is applied to that sorted group.
|
|
11
|
-
* To order the entire stream, key by the same value for all elements such as null.
|
|
12
|
-
*
|
|
13
|
-
* @param comparator - A function that compares two elements
|
|
14
|
-
* @param options - An optional object containing limit and offset properties
|
|
15
|
-
* @returns A piped operator that limits the number of results
|
|
16
|
-
*/
|
|
17
|
-
export declare function topK<KType extends (T extends KeyValue<infer K, infer _V> ? K : never), V1Type extends (T extends KeyValue<KType, infer V> ? V : never), T>(comparator: (a: V1Type, b: V1Type) => number, options?: TopKOptions): PipedOperator<T, T>;
|
|
18
|
-
/**
|
|
19
|
-
* Limits the number of results based on a comparator, with optional offset.
|
|
20
|
-
* This works on a keyed stream, where the key is the first element of the tuple
|
|
21
|
-
* The ordering is withing a key group, i.e. elements are sorted within a key group
|
|
22
|
-
* and the limit + offset is applied to that sorted group.
|
|
23
|
-
* To order the entire stream, key by the same value for all elements such as null.
|
|
24
|
-
* Adds the index of the element to the result as [key, [value, index]]
|
|
25
|
-
*
|
|
26
|
-
* @param comparator - A function that compares two elements
|
|
27
|
-
* @param options - An optional object containing limit and offset properties
|
|
28
|
-
* @returns A piped operator that orders the elements and limits the number of results
|
|
29
|
-
*/
|
|
30
|
-
export declare function topKWithIndex<KType extends (T extends KeyValue<infer K, infer _V> ? K : never), V1Type extends (T extends KeyValue<KType, infer V> ? V : never), T>(comparator: (a: V1Type, b: V1Type) => number, options?: TopKOptions): PipedOperator<T, KeyValue<KType, [
|
|
31
|
-
V1Type,
|
|
32
|
-
number
|
|
33
|
-
]>>;
|
|
34
|
-
export {};
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { TopKWithFractionalIndexOperator, TopKWithFractionalIndexOptions } from "./topKWithFractionalIndex.cjs";
|
|
2
|
-
import { IndexedValue, TopK } from "./topKArray.cjs";
|
|
3
|
-
import { PipedOperator } from "../types.cjs";
|
|
4
|
-
export declare function loadBTree(): Promise<void>;
|
|
5
|
-
/**
|
|
6
|
-
* Operator for fractional indexed topK operations
|
|
7
|
-
* This operator maintains fractional indices for sorted elements
|
|
8
|
-
* and only updates indices when elements move position
|
|
9
|
-
*/
|
|
10
|
-
export declare class TopKWithFractionalIndexBTreeOperator<K extends string | number, T> extends TopKWithFractionalIndexOperator<K, T> {
|
|
11
|
-
protected createTopK(offset: number, limit: number, comparator: (a: [
|
|
12
|
-
K,
|
|
13
|
-
T
|
|
14
|
-
], b: [
|
|
15
|
-
K,
|
|
16
|
-
T
|
|
17
|
-
]) => number): TopK<[
|
|
18
|
-
K,
|
|
19
|
-
T
|
|
20
|
-
]>;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Limits the number of results based on a comparator, with optional offset.
|
|
24
|
-
* This works on a keyed stream, where the key is the first element of the tuple.
|
|
25
|
-
* The ordering is within a key group, i.e. elements are sorted within a key group
|
|
26
|
-
* and the limit + offset is applied to that sorted group.
|
|
27
|
-
* To order the entire stream, key by the same value for all elements such as null.
|
|
28
|
-
*
|
|
29
|
-
* Uses fractional indexing to minimize the number of changes when elements move positions.
|
|
30
|
-
* Each element is assigned a fractional index that is lexicographically sortable.
|
|
31
|
-
* When elements move, only the indices of the moved elements are updated, not all elements.
|
|
32
|
-
*
|
|
33
|
-
* @param comparator - A function that compares two elements
|
|
34
|
-
* @param options - An optional object containing limit and offset properties
|
|
35
|
-
* @returns A piped operator that orders the elements and limits the number of results
|
|
36
|
-
*/
|
|
37
|
-
export declare function topKWithFractionalIndexBTree<KType extends string | number, T>(comparator: (a: T, b: T) => number, options?: TopKWithFractionalIndexOptions): PipedOperator<[
|
|
38
|
-
KType,
|
|
39
|
-
T
|
|
40
|
-
], [
|
|
41
|
-
KType,
|
|
42
|
-
IndexedValue<T>
|
|
43
|
-
]>;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { DifferenceStreamWriter, DifferenceStreamReader } from '../graph.js';
|
|
2
|
-
import { ReduceOperator } from './reduce.js';
|
|
3
|
-
import { IStreamBuilder, KeyValue } from '../types.js';
|
|
4
|
-
/**
|
|
5
|
-
* Operator that counts elements by key (version-free)
|
|
6
|
-
*/
|
|
7
|
-
export declare class CountOperator<K, V> extends ReduceOperator<K, V, number> {
|
|
8
|
-
constructor(id: number, inputA: DifferenceStreamReader<[K, V]>, output: DifferenceStreamWriter<[K, number]>);
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Counts the number of elements by key (version-free)
|
|
12
|
-
*/
|
|
13
|
-
export declare function count<KType extends (T extends KeyValue<infer K, infer _V> ? K : never), VType extends (T extends KeyValue<KType, infer V> ? V : never), T>(): (stream: IStreamBuilder<T>) => IStreamBuilder<KeyValue<KType, number>>;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { DifferenceStreamWriter } from "../graph.js";
|
|
2
|
-
import { StreamBuilder } from "../d2.js";
|
|
3
|
-
import { ReduceOperator } from "./reduce.js";
|
|
4
|
-
class CountOperator extends ReduceOperator {
|
|
5
|
-
constructor(id, inputA, output) {
|
|
6
|
-
const countInner = (vals) => {
|
|
7
|
-
let totalCount = 0;
|
|
8
|
-
for (const [_, diff] of vals) {
|
|
9
|
-
totalCount += diff;
|
|
10
|
-
}
|
|
11
|
-
return [[totalCount, 1]];
|
|
12
|
-
};
|
|
13
|
-
super(id, inputA, output, countInner);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
function count() {
|
|
17
|
-
return (stream) => {
|
|
18
|
-
const output = new StreamBuilder(
|
|
19
|
-
stream.graph,
|
|
20
|
-
new DifferenceStreamWriter()
|
|
21
|
-
);
|
|
22
|
-
const operator = new CountOperator(
|
|
23
|
-
stream.graph.getNextOperatorId(),
|
|
24
|
-
stream.connectReader(),
|
|
25
|
-
output.writer
|
|
26
|
-
);
|
|
27
|
-
stream.graph.addOperator(operator);
|
|
28
|
-
return output;
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
export {
|
|
32
|
-
CountOperator,
|
|
33
|
-
count
|
|
34
|
-
};
|
|
35
|
-
//# sourceMappingURL=count.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"count.js","sources":["../../../src/operators/count.ts"],"sourcesContent":["import { DifferenceStreamWriter } from '../graph.js'\nimport { StreamBuilder } from '../d2.js'\nimport { ReduceOperator } from './reduce.js'\nimport type { DifferenceStreamReader } from '../graph.js'\nimport type { IStreamBuilder, KeyValue } from '../types.js'\n\n/**\n * Operator that counts elements by key (version-free)\n */\nexport class CountOperator<K, V> extends ReduceOperator<K, V, number> {\n constructor(\n id: number,\n inputA: DifferenceStreamReader<[K, V]>,\n output: DifferenceStreamWriter<[K, number]>,\n ) {\n const countInner = (vals: Array<[V, number]>): Array<[number, number]> => {\n let totalCount = 0\n for (const [_, diff] of vals) {\n totalCount += diff\n }\n return [[totalCount, 1]]\n }\n\n super(id, inputA, output, countInner)\n }\n}\n\n/**\n * Counts the number of elements by key (version-free)\n */\nexport function count<\n KType extends (T extends KeyValue<infer K, infer _V> ? K : never),\n VType extends (T extends KeyValue<KType, infer V> ? V : never),\n T,\n>() {\n return (\n stream: IStreamBuilder<T>,\n ): IStreamBuilder<KeyValue<KType, number>> => {\n const output = new StreamBuilder<KeyValue<KType, number>>(\n stream.graph,\n new DifferenceStreamWriter<KeyValue<KType, number>>(),\n )\n const operator = new CountOperator<KType, VType>(\n stream.graph.getNextOperatorId(),\n stream.connectReader() as DifferenceStreamReader<KeyValue<KType, VType>>,\n output.writer,\n )\n stream.graph.addOperator(operator)\n return output\n }\n}\n"],"names":[],"mappings":";;;AASO,MAAM,sBAA4B,eAA6B;AAAA,EACpE,YACE,IACA,QACA,QACA;AACA,UAAM,aAAa,CAAC,SAAsD;AACxE,UAAI,aAAa;AACjB,iBAAW,CAAC,GAAG,IAAI,KAAK,MAAM;AAC5B,sBAAc;AAAA,MAChB;AACA,aAAO,CAAC,CAAC,YAAY,CAAC,CAAC;AAAA,IACzB;AAEA,UAAM,IAAI,QAAQ,QAAQ,UAAU;AAAA,EACtC;AACF;AAKO,SAAS,QAIZ;AACF,SAAO,CACL,WAC4C;AAC5C,UAAM,SAAS,IAAI;AAAA,MACjB,OAAO;AAAA,MACP,IAAI,uBAAA;AAAA,IAAgD;AAEtD,UAAM,WAAW,IAAI;AAAA,MACnB,OAAO,MAAM,kBAAA;AAAA,MACb,OAAO,cAAA;AAAA,MACP,OAAO;AAAA,IAAA;AAET,WAAO,MAAM,YAAY,QAAQ;AACjC,WAAO;AAAA,EACT;AACF;"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { DifferenceStreamWriter, UnaryOperator, DifferenceStreamReader } from '../graph.js';
|
|
2
|
-
import { PipedOperator } from '../types.js';
|
|
3
|
-
/**
|
|
4
|
-
* Operator that logs debug information about the stream
|
|
5
|
-
*/
|
|
6
|
-
export declare class DebugOperator<T> extends UnaryOperator<T> {
|
|
7
|
-
#private;
|
|
8
|
-
constructor(id: number, inputA: DifferenceStreamReader<T>, output: DifferenceStreamWriter<T>, name: string, indent?: boolean);
|
|
9
|
-
run(): void;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Logs debug information about the stream using console.log
|
|
13
|
-
* @param name - The name to prefix debug messages with
|
|
14
|
-
* @param indent - Whether to indent the debug output
|
|
15
|
-
*/
|
|
16
|
-
export declare function debug<T>(name: string, indent?: boolean): PipedOperator<T, T>;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { UnaryOperator, DifferenceStreamWriter } from "../graph.js";
|
|
2
|
-
import { StreamBuilder } from "../d2.js";
|
|
3
|
-
class DebugOperator extends UnaryOperator {
|
|
4
|
-
#name;
|
|
5
|
-
#indent;
|
|
6
|
-
constructor(id, inputA, output, name, indent = false) {
|
|
7
|
-
super(id, inputA, output);
|
|
8
|
-
this.#name = name;
|
|
9
|
-
this.#indent = indent;
|
|
10
|
-
}
|
|
11
|
-
run() {
|
|
12
|
-
for (const message of this.inputMessages()) {
|
|
13
|
-
console.log(`debug ${this.#name} data: ${message.toString(this.#indent)}`);
|
|
14
|
-
this.output.sendData(message);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
function debug(name, indent = false) {
|
|
19
|
-
return (stream) => {
|
|
20
|
-
const output = new StreamBuilder(
|
|
21
|
-
stream.graph,
|
|
22
|
-
new DifferenceStreamWriter()
|
|
23
|
-
);
|
|
24
|
-
const operator = new DebugOperator(
|
|
25
|
-
stream.graph.getNextOperatorId(),
|
|
26
|
-
stream.connectReader(),
|
|
27
|
-
output.writer,
|
|
28
|
-
name,
|
|
29
|
-
indent
|
|
30
|
-
);
|
|
31
|
-
stream.graph.addOperator(operator);
|
|
32
|
-
return output;
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
export {
|
|
36
|
-
DebugOperator,
|
|
37
|
-
debug
|
|
38
|
-
};
|
|
39
|
-
//# sourceMappingURL=debug.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"debug.js","sources":["../../../src/operators/debug.ts"],"sourcesContent":["import { DifferenceStreamWriter, UnaryOperator } from '../graph.js'\nimport { StreamBuilder } from '../d2.js'\nimport type { IStreamBuilder, PipedOperator } from '../types.js'\nimport type { DifferenceStreamReader } from '../graph.js'\n\n/**\n * Operator that logs debug information about the stream\n */\nexport class DebugOperator<T> extends UnaryOperator<T> {\n #name: string\n #indent: boolean\n\n constructor(\n id: number,\n inputA: DifferenceStreamReader<T>,\n output: DifferenceStreamWriter<T>,\n name: string,\n indent: boolean = false,\n ) {\n super(id, inputA, output)\n this.#name = name\n this.#indent = indent\n }\n\n run(): void {\n for (const message of this.inputMessages()) {\n console.log(`debug ${this.#name} data: ${message.toString(this.#indent)}`)\n this.output.sendData(message)\n }\n }\n}\n\n/**\n * Logs debug information about the stream using console.log\n * @param name - The name to prefix debug messages with\n * @param indent - Whether to indent the debug output\n */\nexport function debug<T>(\n name: string,\n indent: boolean = false,\n): PipedOperator<T, T> {\n return (stream: IStreamBuilder<T>): IStreamBuilder<T> => {\n const output = new StreamBuilder<T>(\n stream.graph,\n new DifferenceStreamWriter<T>(),\n )\n const operator = new DebugOperator<T>(\n stream.graph.getNextOperatorId(),\n stream.connectReader(),\n output.writer,\n name,\n indent,\n )\n stream.graph.addOperator(operator)\n return output\n }\n}\n"],"names":[],"mappings":";;AAQO,MAAM,sBAAyB,cAAiB;AAAA,EACrD;AAAA,EACA;AAAA,EAEA,YACE,IACA,QACA,QACA,MACA,SAAkB,OAClB;AACA,UAAM,IAAI,QAAQ,MAAM;AACxB,SAAK,QAAQ;AACb,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA,MAAY;AACV,eAAW,WAAW,KAAK,iBAAiB;AAC1C,cAAQ,IAAI,SAAS,KAAK,KAAK,UAAU,QAAQ,SAAS,KAAK,OAAO,CAAC,EAAE;AACzE,WAAK,OAAO,SAAS,OAAO;AAAA,IAC9B;AAAA,EACF;AACF;AAOO,SAAS,MACd,MACA,SAAkB,OACG;AACrB,SAAO,CAAC,WAAiD;AACvD,UAAM,SAAS,IAAI;AAAA,MACjB,OAAO;AAAA,MACP,IAAI,uBAAA;AAAA,IAA0B;AAEhC,UAAM,WAAW,IAAI;AAAA,MACnB,OAAO,MAAM,kBAAA;AAAA,MACb,OAAO,cAAA;AAAA,MACP,OAAO;AAAA,MACP;AAAA,MACA;AAAA,IAAA;AAEF,WAAO,MAAM,YAAY,QAAQ;AACjC,WAAO;AAAA,EACT;AACF;"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { IStreamBuilder, KeyValue, PipedOperator } from '../types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Filters the elements of a keyed stream, by keys of another stream.
|
|
4
|
-
* This allows you to build pipelies where you have multiple outputs that are related,
|
|
5
|
-
* such as a streams of issues and comments for a project.
|
|
6
|
-
*
|
|
7
|
-
* @param other - The other stream to filter by, which must have the same key type as the input stream
|
|
8
|
-
*/
|
|
9
|
-
export declare function filterBy<K, V1 extends (T extends KeyValue<infer _KT, infer VT> ? VT : never), T>(other: IStreamBuilder<KeyValue<K, unknown>>): PipedOperator<T, KeyValue<K, V1>>;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { map } from "./map.js";
|
|
2
|
-
import { innerJoin } from "./join.js";
|
|
3
|
-
import { consolidate } from "./consolidate.js";
|
|
4
|
-
function filterBy(other) {
|
|
5
|
-
return (stream) => {
|
|
6
|
-
const otherKeys = other.pipe(
|
|
7
|
-
map(([key, _]) => [key, null])
|
|
8
|
-
);
|
|
9
|
-
return stream.pipe(
|
|
10
|
-
innerJoin(otherKeys),
|
|
11
|
-
map(([key, [value, _]]) => [key, value]),
|
|
12
|
-
consolidate()
|
|
13
|
-
);
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
export {
|
|
17
|
-
filterBy
|
|
18
|
-
};
|
|
19
|
-
//# sourceMappingURL=filterBy.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"filterBy.js","sources":["../../../src/operators/filterBy.ts"],"sourcesContent":["import { map } from './map.js'\nimport { innerJoin } from './join.js'\nimport { consolidate } from './consolidate.js'\nimport type { IStreamBuilder, KeyValue, PipedOperator } from '../types.js'\n\n/**\n * Filters the elements of a keyed stream, by keys of another stream.\n * This allows you to build pipelies where you have multiple outputs that are related,\n * such as a streams of issues and comments for a project.\n *\n * @param other - The other stream to filter by, which must have the same key type as the input stream\n */\nexport function filterBy<\n K,\n V1 extends (T extends KeyValue<infer _KT, infer VT> ? VT : never),\n T,\n>(\n other: IStreamBuilder<KeyValue<K, unknown>>,\n): PipedOperator<T, KeyValue<K, V1>> {\n return (stream: IStreamBuilder<T>): IStreamBuilder<KeyValue<K, V1>> => {\n const otherKeys = other.pipe(\n map(([key, _]) => [key, null] as KeyValue<K, null>),\n )\n return stream.pipe(\n innerJoin(otherKeys),\n map(([key, [value, _]]) => [key, value] as KeyValue<K, V1>),\n consolidate(),\n )\n }\n}\n"],"names":[],"mappings":";;;AAYO,SAAS,SAKd,OACmC;AACnC,SAAO,CAAC,WAA+D;AACrE,UAAM,YAAY,MAAM;AAAA,MACtB,IAAI,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI,CAAsB;AAAA,IAAA;AAEpD,WAAO,OAAO;AAAA,MACZ,UAAU,SAAS;AAAA,MACnB,IAAI,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,KAAK,CAAoB;AAAA,MAC1D,YAAA;AAAA,IAAY;AAAA,EAEhB;AACF;"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { PipedOperator } from '../types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Type for a keyed value
|
|
4
|
-
*/
|
|
5
|
-
export type Keyed<K, V> = [K, V];
|
|
6
|
-
/**
|
|
7
|
-
* Takes an unkeyed input and returns a keyed result
|
|
8
|
-
* @param keyFn - Function to generate the key for each value
|
|
9
|
-
*/
|
|
10
|
-
export declare function keyBy<T, K>(keyFn: (value: T) => K): PipedOperator<T, Keyed<K, T>>;
|
|
11
|
-
/**
|
|
12
|
-
* Removes the key from a keyed stream
|
|
13
|
-
*/
|
|
14
|
-
export declare function unkey<K, V>(): PipedOperator<Keyed<K, V>, V>;
|
|
15
|
-
/**
|
|
16
|
-
* Takes a keyed input and rekeys it with a new key
|
|
17
|
-
* @param keyFn - Function to generate the new key for each value
|
|
18
|
-
*/
|
|
19
|
-
export declare function rekey<K1, K2, V>(keyFn: (value: V) => K2): PipedOperator<Keyed<K1, V>, Keyed<K2, V>>;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { map } from "./map.js";
|
|
2
|
-
function keyBy(keyFn) {
|
|
3
|
-
return map((value) => [keyFn(value), value]);
|
|
4
|
-
}
|
|
5
|
-
function unkey() {
|
|
6
|
-
return map(([_, value]) => value);
|
|
7
|
-
}
|
|
8
|
-
function rekey(keyFn) {
|
|
9
|
-
return map(([_, value]) => [keyFn(value), value]);
|
|
10
|
-
}
|
|
11
|
-
export {
|
|
12
|
-
keyBy,
|
|
13
|
-
rekey,
|
|
14
|
-
unkey
|
|
15
|
-
};
|
|
16
|
-
//# sourceMappingURL=keying.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"keying.js","sources":["../../../src/operators/keying.ts"],"sourcesContent":["import { map } from './map.js'\nimport type { PipedOperator } from '../types.js'\n\n/**\n * Type for a keyed value\n */\nexport type Keyed<K, V> = [K, V]\n\n/**\n * Takes an unkeyed input and returns a keyed result\n * @param keyFn - Function to generate the key for each value\n */\nexport function keyBy<T, K>(\n keyFn: (value: T) => K,\n): PipedOperator<T, Keyed<K, T>> {\n return map((value: T): Keyed<K, T> => [keyFn(value), value])\n}\n\n/**\n * Removes the key from a keyed stream\n */\nexport function unkey<K, V>(): PipedOperator<Keyed<K, V>, V> {\n return map(([_, value]: Keyed<K, V>): V => value)\n}\n\n/**\n * Takes a keyed input and rekeys it with a new key\n * @param keyFn - Function to generate the new key for each value\n */\nexport function rekey<K1, K2, V>(\n keyFn: (value: V) => K2,\n): PipedOperator<Keyed<K1, V>, Keyed<K2, V>> {\n return map(([_, value]: Keyed<K1, V>): Keyed<K2, V> => [keyFn(value), value])\n}\n"],"names":[],"mappings":";AAYO,SAAS,MACd,OAC+B;AAC/B,SAAO,IAAI,CAAC,UAA0B,CAAC,MAAM,KAAK,GAAG,KAAK,CAAC;AAC7D;AAKO,SAAS,QAA6C;AAC3D,SAAO,IAAI,CAAC,CAAC,GAAG,KAAK,MAAsB,KAAK;AAClD;AAMO,SAAS,MACd,OAC2C;AAC3C,SAAO,IAAI,CAAC,CAAC,GAAG,KAAK,MAAkC,CAAC,MAAM,KAAK,GAAG,KAAK,CAAC;AAC9E;"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { LinearUnaryOperator } from '../graph.js';
|
|
2
|
-
import { PipedOperator } from '../types.js';
|
|
3
|
-
import { MultiSet } from '../multiset.js';
|
|
4
|
-
/**
|
|
5
|
-
* Operator that negates the multiplicities in the input stream
|
|
6
|
-
*/
|
|
7
|
-
export declare class NegateOperator<T> extends LinearUnaryOperator<T, T> {
|
|
8
|
-
inner(collection: MultiSet<T>): MultiSet<T>;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Negates the multiplicities in the input stream
|
|
12
|
-
*/
|
|
13
|
-
export declare function negate<T>(): PipedOperator<T, T>;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { LinearUnaryOperator, DifferenceStreamWriter } from "../graph.js";
|
|
2
|
-
import { StreamBuilder } from "../d2.js";
|
|
3
|
-
class NegateOperator extends LinearUnaryOperator {
|
|
4
|
-
inner(collection) {
|
|
5
|
-
return collection.negate();
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
function negate() {
|
|
9
|
-
return (stream) => {
|
|
10
|
-
const output = new StreamBuilder(
|
|
11
|
-
stream.graph,
|
|
12
|
-
new DifferenceStreamWriter()
|
|
13
|
-
);
|
|
14
|
-
const operator = new NegateOperator(
|
|
15
|
-
stream.graph.getNextOperatorId(),
|
|
16
|
-
stream.connectReader(),
|
|
17
|
-
output.writer
|
|
18
|
-
);
|
|
19
|
-
stream.graph.addOperator(operator);
|
|
20
|
-
return output;
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
export {
|
|
24
|
-
NegateOperator,
|
|
25
|
-
negate
|
|
26
|
-
};
|
|
27
|
-
//# sourceMappingURL=negate.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"negate.js","sources":["../../../src/operators/negate.ts"],"sourcesContent":["import { DifferenceStreamWriter, LinearUnaryOperator } from '../graph.js'\nimport { StreamBuilder } from '../d2.js'\nimport type { IStreamBuilder, PipedOperator } from '../types.js'\nimport type { MultiSet } from '../multiset.js'\n\n/**\n * Operator that negates the multiplicities in the input stream\n */\nexport class NegateOperator<T> extends LinearUnaryOperator<T, T> {\n inner(collection: MultiSet<T>): MultiSet<T> {\n return collection.negate()\n }\n}\n\n/**\n * Negates the multiplicities in the input stream\n */\nexport function negate<T>(): PipedOperator<T, T> {\n return (stream: IStreamBuilder<T>): IStreamBuilder<T> => {\n const output = new StreamBuilder<T>(\n stream.graph,\n new DifferenceStreamWriter<T>(),\n )\n const operator = new NegateOperator<T>(\n stream.graph.getNextOperatorId(),\n stream.connectReader(),\n output.writer,\n )\n stream.graph.addOperator(operator)\n return output\n }\n}\n"],"names":[],"mappings":";;AAQO,MAAM,uBAA0B,oBAA0B;AAAA,EAC/D,MAAM,YAAsC;AAC1C,WAAO,WAAW,OAAA;AAAA,EACpB;AACF;AAKO,SAAS,SAAiC;AAC/C,SAAO,CAAC,WAAiD;AACvD,UAAM,SAAS,IAAI;AAAA,MACjB,OAAO;AAAA,MACP,IAAI,uBAAA;AAAA,IAA0B;AAEhC,UAAM,WAAW,IAAI;AAAA,MACnB,OAAO,MAAM,kBAAA;AAAA,MACb,OAAO,cAAA;AAAA,MACP,OAAO;AAAA,IAAA;AAET,WAAO,MAAM,YAAY,QAAQ;AACjC,WAAO;AAAA,EACT;AACF;"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { KeyValue, PipedOperator } from '../types.js';
|
|
2
|
-
interface TopKOptions {
|
|
3
|
-
limit?: number;
|
|
4
|
-
offset?: number;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Limits the number of results based on a comparator, with optional offset.
|
|
8
|
-
* This works on a keyed stream, where the key is the first element of the tuple
|
|
9
|
-
* The ordering is withing a key group, i.e. elements are sorted within a key group
|
|
10
|
-
* and the limit + offset is applied to that sorted group.
|
|
11
|
-
* To order the entire stream, key by the same value for all elements such as null.
|
|
12
|
-
*
|
|
13
|
-
* @param comparator - A function that compares two elements
|
|
14
|
-
* @param options - An optional object containing limit and offset properties
|
|
15
|
-
* @returns A piped operator that limits the number of results
|
|
16
|
-
*/
|
|
17
|
-
export declare function topK<KType extends (T extends KeyValue<infer K, infer _V> ? K : never), V1Type extends (T extends KeyValue<KType, infer V> ? V : never), T>(comparator: (a: V1Type, b: V1Type) => number, options?: TopKOptions): PipedOperator<T, T>;
|
|
18
|
-
/**
|
|
19
|
-
* Limits the number of results based on a comparator, with optional offset.
|
|
20
|
-
* This works on a keyed stream, where the key is the first element of the tuple
|
|
21
|
-
* The ordering is withing a key group, i.e. elements are sorted within a key group
|
|
22
|
-
* and the limit + offset is applied to that sorted group.
|
|
23
|
-
* To order the entire stream, key by the same value for all elements such as null.
|
|
24
|
-
* Adds the index of the element to the result as [key, [value, index]]
|
|
25
|
-
*
|
|
26
|
-
* @param comparator - A function that compares two elements
|
|
27
|
-
* @param options - An optional object containing limit and offset properties
|
|
28
|
-
* @returns A piped operator that orders the elements and limits the number of results
|
|
29
|
-
*/
|
|
30
|
-
export declare function topKWithIndex<KType extends (T extends KeyValue<infer K, infer _V> ? K : never), V1Type extends (T extends KeyValue<KType, infer V> ? V : never), T>(comparator: (a: V1Type, b: V1Type) => number, options?: TopKOptions): PipedOperator<T, KeyValue<KType, [V1Type, number]>>;
|
|
31
|
-
export {};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { MultiSet } from "../multiset.js";
|
|
2
|
-
import { reduce } from "./reduce.js";
|
|
3
|
-
function topK(comparator, options) {
|
|
4
|
-
const limit = options?.limit ?? Infinity;
|
|
5
|
-
const offset = options?.offset ?? 0;
|
|
6
|
-
return (stream) => {
|
|
7
|
-
const reduced = stream.pipe(
|
|
8
|
-
reduce((values) => {
|
|
9
|
-
const consolidated = new MultiSet(values).consolidate();
|
|
10
|
-
const sortedValues = consolidated.getInner().sort((a, b) => comparator(a[0], b[0]));
|
|
11
|
-
return sortedValues.slice(offset, offset + limit);
|
|
12
|
-
})
|
|
13
|
-
);
|
|
14
|
-
return reduced;
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
function topKWithIndex(comparator, options) {
|
|
18
|
-
const limit = options?.limit ?? Infinity;
|
|
19
|
-
const offset = options?.offset ?? 0;
|
|
20
|
-
return (stream) => {
|
|
21
|
-
const reduced = stream.pipe(
|
|
22
|
-
reduce((values) => {
|
|
23
|
-
const consolidated = new MultiSet(values).consolidate();
|
|
24
|
-
let i = offset;
|
|
25
|
-
const sortedValues = consolidated.getInner().sort((a, b) => comparator(a[0], b[0])).slice(offset, offset + limit).map(([value, multiplicity]) => [
|
|
26
|
-
[value, i++],
|
|
27
|
-
multiplicity
|
|
28
|
-
]);
|
|
29
|
-
return sortedValues;
|
|
30
|
-
})
|
|
31
|
-
);
|
|
32
|
-
return reduced;
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
export {
|
|
36
|
-
topK,
|
|
37
|
-
topKWithIndex
|
|
38
|
-
};
|
|
39
|
-
//# sourceMappingURL=topK.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"topK.js","sources":["../../../src/operators/topK.ts"],"sourcesContent":["import { MultiSet } from '../multiset.js'\nimport { reduce } from './reduce.js'\nimport type { IStreamBuilder, KeyValue, PipedOperator } from '../types'\n\ninterface TopKOptions {\n limit?: number\n offset?: number\n}\n\n/**\n * Limits the number of results based on a comparator, with optional offset.\n * This works on a keyed stream, where the key is the first element of the tuple\n * The ordering is withing a key group, i.e. elements are sorted within a key group\n * and the limit + offset is applied to that sorted group.\n * To order the entire stream, key by the same value for all elements such as null.\n *\n * @param comparator - A function that compares two elements\n * @param options - An optional object containing limit and offset properties\n * @returns A piped operator that limits the number of results\n */\nexport function topK<\n KType extends (T extends KeyValue<infer K, infer _V> ? K : never),\n V1Type extends (T extends KeyValue<KType, infer V> ? V : never),\n T,\n>(\n comparator: (a: V1Type, b: V1Type) => number,\n options?: TopKOptions,\n): PipedOperator<T, T> {\n const limit = options?.limit ?? Infinity\n const offset = options?.offset ?? 0\n\n return (stream: IStreamBuilder<T>): IStreamBuilder<T> => {\n const reduced = stream.pipe(\n reduce((values) => {\n // `values` is a list of tuples, first element is the value, second is the multiplicity\n const consolidated = new MultiSet(values).consolidate()\n const sortedValues = consolidated\n .getInner()\n .sort((a, b) => comparator(a[0] as V1Type, b[0] as V1Type))\n return sortedValues.slice(offset, offset + limit)\n }),\n )\n return reduced as IStreamBuilder<T>\n }\n}\n\n/**\n * Limits the number of results based on a comparator, with optional offset.\n * This works on a keyed stream, where the key is the first element of the tuple\n * The ordering is withing a key group, i.e. elements are sorted within a key group\n * and the limit + offset is applied to that sorted group.\n * To order the entire stream, key by the same value for all elements such as null.\n * Adds the index of the element to the result as [key, [value, index]]\n *\n * @param comparator - A function that compares two elements\n * @param options - An optional object containing limit and offset properties\n * @returns A piped operator that orders the elements and limits the number of results\n */\nexport function topKWithIndex<\n KType extends (T extends KeyValue<infer K, infer _V> ? K : never),\n V1Type extends (T extends KeyValue<KType, infer V> ? V : never),\n T,\n>(\n comparator: (a: V1Type, b: V1Type) => number,\n options?: TopKOptions,\n): PipedOperator<T, KeyValue<KType, [V1Type, number]>> {\n const limit = options?.limit ?? Infinity\n const offset = options?.offset ?? 0\n\n return (\n stream: IStreamBuilder<T>,\n ): IStreamBuilder<KeyValue<KType, [V1Type, number]>> => {\n const reduced = stream.pipe(\n reduce<KType, V1Type, [V1Type, number], T>((values) => {\n // `values` is a list of tuples, first element is the value, second is the multiplicity\n const consolidated = new MultiSet(values).consolidate()\n let i = offset\n const sortedValues = consolidated\n .getInner()\n .sort((a, b) => comparator(a[0], b[0]))\n .slice(offset, offset + limit)\n .map(([value, multiplicity]): [[V1Type, number], number] => [\n [value, i++],\n multiplicity,\n ])\n return sortedValues\n }),\n )\n return reduced\n }\n}\n"],"names":[],"mappings":";;AAoBO,SAAS,KAKd,YACA,SACqB;AACrB,QAAM,QAAQ,SAAS,SAAS;AAChC,QAAM,SAAS,SAAS,UAAU;AAElC,SAAO,CAAC,WAAiD;AACvD,UAAM,UAAU,OAAO;AAAA,MACrB,OAAO,CAAC,WAAW;AAEjB,cAAM,eAAe,IAAI,SAAS,MAAM,EAAE,YAAA;AAC1C,cAAM,eAAe,aAClB,SAAA,EACA,KAAK,CAAC,GAAG,MAAM,WAAW,EAAE,CAAC,GAAa,EAAE,CAAC,CAAW,CAAC;AAC5D,eAAO,aAAa,MAAM,QAAQ,SAAS,KAAK;AAAA,MAClD,CAAC;AAAA,IAAA;AAEH,WAAO;AAAA,EACT;AACF;AAcO,SAAS,cAKd,YACA,SACqD;AACrD,QAAM,QAAQ,SAAS,SAAS;AAChC,QAAM,SAAS,SAAS,UAAU;AAElC,SAAO,CACL,WACsD;AACtD,UAAM,UAAU,OAAO;AAAA,MACrB,OAA2C,CAAC,WAAW;AAErD,cAAM,eAAe,IAAI,SAAS,MAAM,EAAE,YAAA;AAC1C,YAAI,IAAI;AACR,cAAM,eAAe,aAClB,SAAA,EACA,KAAK,CAAC,GAAG,MAAM,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EACrC,MAAM,QAAQ,SAAS,KAAK,EAC5B,IAAI,CAAC,CAAC,OAAO,YAAY,MAAkC;AAAA,UAC1D,CAAC,OAAO,GAAG;AAAA,UACX;AAAA,QAAA,CACD;AACH,eAAO;AAAA,MACT,CAAC;AAAA,IAAA;AAEH,WAAO;AAAA,EACT;AACF;"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { TopKWithFractionalIndexOperator, TopKWithFractionalIndexOptions } from './topKWithFractionalIndex.js';
|
|
2
|
-
import { IndexedValue, TopK } from './topKArray.js';
|
|
3
|
-
import { PipedOperator } from '../types.js';
|
|
4
|
-
export declare function loadBTree(): Promise<void>;
|
|
5
|
-
/**
|
|
6
|
-
* Operator for fractional indexed topK operations
|
|
7
|
-
* This operator maintains fractional indices for sorted elements
|
|
8
|
-
* and only updates indices when elements move position
|
|
9
|
-
*/
|
|
10
|
-
export declare class TopKWithFractionalIndexBTreeOperator<K extends string | number, T> extends TopKWithFractionalIndexOperator<K, T> {
|
|
11
|
-
protected createTopK(offset: number, limit: number, comparator: (a: [K, T], b: [K, T]) => number): TopK<[K, T]>;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Limits the number of results based on a comparator, with optional offset.
|
|
15
|
-
* This works on a keyed stream, where the key is the first element of the tuple.
|
|
16
|
-
* The ordering is within a key group, i.e. elements are sorted within a key group
|
|
17
|
-
* and the limit + offset is applied to that sorted group.
|
|
18
|
-
* To order the entire stream, key by the same value for all elements such as null.
|
|
19
|
-
*
|
|
20
|
-
* Uses fractional indexing to minimize the number of changes when elements move positions.
|
|
21
|
-
* Each element is assigned a fractional index that is lexicographically sortable.
|
|
22
|
-
* When elements move, only the indices of the moved elements are updated, not all elements.
|
|
23
|
-
*
|
|
24
|
-
* @param comparator - A function that compares two elements
|
|
25
|
-
* @param options - An optional object containing limit and offset properties
|
|
26
|
-
* @returns A piped operator that orders the elements and limits the number of results
|
|
27
|
-
*/
|
|
28
|
-
export declare function topKWithFractionalIndexBTree<KType extends string | number, T>(comparator: (a: T, b: T) => number, options?: TopKWithFractionalIndexOptions): PipedOperator<[KType, T], [KType, IndexedValue<T>]>;
|