@jahed/sparql-engine
Version:
SPARQL query engine for servers and web browsers.
36 lines • 1.26 kB
JavaScript
/**
* A HashJoinTable is used by a Hash-based join to save set of bindings corresponding to a joinKey.
* All bindings corresponding to the save value of the joinKey are aggregated in a list.
*/
export default class HashJoinTable {
_content;
constructor() {
this._content = new Map();
}
/**
* Register a pair (value, bindings).
* @param key - Key used to save the bindings
* @param bindings - Bindings to save
*/
put(key, bindings) {
if (!this._content.has(key)) {
this._content.set(key, []);
}
const old = this._content.get(key);
this._content.set(key, old.concat([bindings]));
}
/**
* Perform a join between a set of bindings and all set of bindings in the table associated with the key.
* Returns an empty list if there is no join results.
* @param key - Key used to fetch set of set of bindings
* @param bindings - Bindings to join with
* @return Join results, or an empty list if there is none.
*/
join(key, bindings) {
if (!this._content.has(key)) {
return [];
}
return this._content.get(key).map((b) => b.union(bindings));
}
}
//# sourceMappingURL=hash-join-table.js.map