[upd] plankton
This commit is contained in:
parent
048d7570d1
commit
901fab3ac4
3 changed files with 641 additions and 11 deletions
163
lib/plankton/plankton.d.ts
vendored
163
lib/plankton/plankton.d.ts
vendored
|
@ -1,15 +1,15 @@
|
||||||
/**
|
/**
|
||||||
* @author fenris
|
* @author fenris
|
||||||
*/
|
*/
|
||||||
type int = number;
|
declare type int = number;
|
||||||
/**
|
/**
|
||||||
* @author fenris
|
* @author fenris
|
||||||
*/
|
*/
|
||||||
type float = number;
|
declare type float = number;
|
||||||
/**
|
/**
|
||||||
* @author fenris
|
* @author fenris
|
||||||
*/
|
*/
|
||||||
type type_date = {
|
declare type type_date = {
|
||||||
year: int;
|
year: int;
|
||||||
month: int;
|
month: int;
|
||||||
day: int;
|
day: int;
|
||||||
|
@ -17,7 +17,7 @@ type type_date = {
|
||||||
/**
|
/**
|
||||||
* @author fenris
|
* @author fenris
|
||||||
*/
|
*/
|
||||||
type type_time = {
|
declare type type_time = {
|
||||||
hour: int;
|
hour: int;
|
||||||
minute: int;
|
minute: int;
|
||||||
second: int;
|
second: int;
|
||||||
|
@ -25,7 +25,7 @@ type type_time = {
|
||||||
/**
|
/**
|
||||||
* @author fenris
|
* @author fenris
|
||||||
*/
|
*/
|
||||||
type type_datetimeobject = {
|
declare type type_datetimeobject = {
|
||||||
date: type_date;
|
date: type_date;
|
||||||
time: type_time;
|
time: type_time;
|
||||||
};
|
};
|
||||||
|
@ -45,7 +45,7 @@ declare namespace lib_plankton.base {
|
||||||
/**
|
/**
|
||||||
* @author fenris
|
* @author fenris
|
||||||
*/
|
*/
|
||||||
type type_pseudopointer<type_value> = {
|
declare type type_pseudopointer<type_value> = {
|
||||||
value: type_value;
|
value: type_value;
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
|
@ -2209,7 +2209,7 @@ declare namespace lib_plankton.storage.memory {
|
||||||
clear(): Promise<void>;
|
clear(): Promise<void>;
|
||||||
write(key: any, value: any): Promise<boolean>;
|
write(key: any, value: any): Promise<boolean>;
|
||||||
delete(key: any): Promise<void>;
|
delete(key: any): Promise<void>;
|
||||||
read(key: any): Promise<Awaited<type_item>>;
|
read(key: any): Promise<type_item>;
|
||||||
search(term: any): Promise<{
|
search(term: any): Promise<{
|
||||||
key: string;
|
key: string;
|
||||||
preview: string;
|
preview: string;
|
||||||
|
@ -4187,6 +4187,155 @@ declare namespace lib_plankton.bcrypt {
|
||||||
*/
|
*/
|
||||||
function compare(password_shall_image: string, password_is: string): Promise<boolean>;
|
function compare(password_shall_image: string, password_is: string): Promise<boolean>;
|
||||||
}
|
}
|
||||||
|
declare namespace lib_plankton.map {
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
type type_pair<type_key, type_value> = {
|
||||||
|
key: type_key;
|
||||||
|
value: type_value;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* @author fenris
|
||||||
|
*/
|
||||||
|
type type_map<type_key, type_value> = {
|
||||||
|
size: (() => int);
|
||||||
|
has: ((key: type_key) => boolean);
|
||||||
|
get: ((key: type_key, fallback?: lib_plankton.pod.type_pod<type_value>) => type_value);
|
||||||
|
set: ((key: type_key, value: type_value) => void);
|
||||||
|
delete: ((key: type_key) => void);
|
||||||
|
iterate: ((procedure: ((value: type_value, key?: type_key) => void)) => void);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
declare namespace lib_plankton.map {
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function clear<type_key, type_value>(map: type_map<type_key, type_value>): void;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function keys<type_key, type_value>(map: type_map<type_key, type_value>): Array<type_key>;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function values<type_key, type_value>(map: type_map<type_key, type_value>): Array<type_value>;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function dump<type_key, type_value>(map: type_map<type_key, type_value>): Array<type_pair<type_key, type_value>>;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function show<type_key, type_value>(map: type_map<type_key, type_value>, options?: {
|
||||||
|
show_key?: ((key: type_key) => string);
|
||||||
|
show_value?: ((value: type_value) => string);
|
||||||
|
}): string;
|
||||||
|
}
|
||||||
|
declare namespace lib_plankton.map.simplemap {
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
type type_subject<type_value> = {
|
||||||
|
data: Record<string, type_value>;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function make<type_value>(options?: {
|
||||||
|
data?: Record<string, type_value>;
|
||||||
|
}): type_subject<type_value>;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function size<type_value>(subject: type_subject<type_value>): int;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function has<type_value>(subject: type_subject<type_value>, key: string): boolean;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function get_safe<type_value>(subject: type_subject<type_value>, key: string): lib_plankton.pod.type_pod<type_value>;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function get<type_value>(subject: type_subject<type_value>, key: string, fallback?: lib_plankton.pod.type_pod<type_value>): type_value;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function set<type_value>(subject: type_subject<type_value>, key: string, value: type_value): void;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function delete_<type_value>(subject: type_subject<type_value>, key: string): void;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function iterate<type_value>(subject: type_subject<type_value>, procedure: ((value?: type_value, key?: string) => void)): void;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function implementation_map<type_value>(subject: type_subject<type_value>): type_map<string, type_value>;
|
||||||
|
}
|
||||||
|
declare namespace lib_plankton.map.hashmap {
|
||||||
|
/**
|
||||||
|
* we base the hashmap on a simplemap, whos keys are the hashes and whos values are the key/value-pairs
|
||||||
|
*/
|
||||||
|
type type_subject<type_key, type_value> = {
|
||||||
|
hashing: ((key: type_key) => string);
|
||||||
|
core: lib_plankton.map.simplemap.type_subject<type_pair<type_key, type_value>>;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function make<type_key, type_value>(hashing: ((key: type_key) => string), options?: {
|
||||||
|
pairs?: Array<type_pair<type_key, type_value>>;
|
||||||
|
}): type_subject<type_key, type_value>;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function size<type_key, type_value>(subject: type_subject<type_key, type_value>): int;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function has<type_key, type_value>(subject: type_subject<type_key, type_value>, key: type_key): boolean;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function get<type_key, type_value>(subject: type_subject<type_key, type_value>, key: type_key, fallback?: lib_plankton.pod.type_pod<type_value>): type_value;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function set<type_key, type_value>(subject: type_subject<type_key, type_value>, key: type_key, value: type_value): void;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function delete_<type_key, type_value>(subject: type_subject<type_key, type_value>, key: type_key): void;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function iterate<type_key, type_value>(subject: type_subject<type_key, type_value>, procedure: ((value?: type_value, key?: type_key) => void)): void;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function implementation_map<type_key, type_value>(subject: type_subject<type_key, type_value>): type_map<type_key, type_value>;
|
||||||
|
}
|
||||||
|
declare namespace lib_plankton.map.collatemap {
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
type type_collation<type_key> = ((key1: type_key, key2: type_key) => boolean);
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
export type type_subject<type_key, type_value> = {
|
||||||
|
collation: type_collation<type_key>;
|
||||||
|
pairs: Array<type_pair<type_key, type_value>>;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
export function make<type_key, type_value>(collation: type_collation<type_key>, options?: {
|
||||||
|
pairs?: Array<type_pair<type_key, type_value>>;
|
||||||
|
}): type_subject<type_key, type_value>;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
export function size<type_key, type_value>(subject: type_subject<type_key, type_value>): int;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
export function has<type_key, type_value>(subject: type_subject<type_key, type_value>, key: type_key): boolean;
|
||||||
|
/**
|
||||||
|
* @todo use .find
|
||||||
|
*/
|
||||||
|
export function get<type_key, type_value>(subject: type_subject<type_key, type_value>, key: type_key, fallback?: lib_plankton.pod.type_pod<type_value>): type_value;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
export function set<type_key, type_value>(subject: type_subject<type_key, type_value>, key: type_key, value: type_value): void;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
export function delete_<type_key, type_value>(subject: type_subject<type_key, type_value>, key: type_key): void;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
export function iterate<type_key, type_value>(subject: type_subject<type_key, type_value>, function_: ((value?: type_value, key?: type_key) => void)): void;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
export function implementation_map<type_key, type_value>(subject: type_subject<type_key, type_value>): type_map<type_key, type_value>;
|
||||||
|
export {};
|
||||||
|
}
|
||||||
declare namespace lib_plankton.base64 {
|
declare namespace lib_plankton.base64 {
|
||||||
/**
|
/**
|
||||||
* @author fenris
|
* @author fenris
|
||||||
|
|
|
@ -1568,7 +1568,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||||
function step(op) {
|
function step(op) {
|
||||||
if (f) throw new TypeError("Generator is already executing.");
|
if (f) throw new TypeError("Generator is already executing.");
|
||||||
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
while (_) try {
|
||||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||||
switch (op[0]) {
|
switch (op[0]) {
|
||||||
|
@ -6564,7 +6564,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||||
function step(op) {
|
function step(op) {
|
||||||
if (f) throw new TypeError("Generator is already executing.");
|
if (f) throw new TypeError("Generator is already executing.");
|
||||||
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
while (_) try {
|
||||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||||
switch (op[0]) {
|
switch (op[0]) {
|
||||||
|
@ -9886,7 +9886,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||||
function step(op) {
|
function step(op) {
|
||||||
if (f) throw new TypeError("Generator is already executing.");
|
if (f) throw new TypeError("Generator is already executing.");
|
||||||
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
while (_) try {
|
||||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||||
switch (op[0]) {
|
switch (op[0]) {
|
||||||
|
@ -14462,7 +14462,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||||
function step(op) {
|
function step(op) {
|
||||||
if (f) throw new TypeError("Generator is already executing.");
|
if (f) throw new TypeError("Generator is already executing.");
|
||||||
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
while (_) try {
|
||||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||||
switch (op[0]) {
|
switch (op[0]) {
|
||||||
|
@ -14560,6 +14560,486 @@ var lib_plankton;
|
||||||
})(bcrypt = lib_plankton.bcrypt || (lib_plankton.bcrypt = {}));
|
})(bcrypt = lib_plankton.bcrypt || (lib_plankton.bcrypt = {}));
|
||||||
})(lib_plankton || (lib_plankton = {}));
|
})(lib_plankton || (lib_plankton = {}));
|
||||||
/*
|
/*
|
||||||
|
This file is part of »bacterio-plankton:map«.
|
||||||
|
|
||||||
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
||||||
|
<info@greenscale.de>
|
||||||
|
|
||||||
|
»bacterio-plankton:map« is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
»bacterio-plankton:map« is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with »bacterio-plankton:map«. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
This file is part of »bacterio-plankton:map«.
|
||||||
|
|
||||||
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
||||||
|
<info@greenscale.de>
|
||||||
|
|
||||||
|
»bacterio-plankton:map« is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
»bacterio-plankton:map« is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with »bacterio-plankton:map«. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
var lib_plankton;
|
||||||
|
(function (lib_plankton) {
|
||||||
|
var map;
|
||||||
|
(function (map_1) {
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function clear(map) {
|
||||||
|
map.iterate(function (value, key) {
|
||||||
|
map["delete"](key);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
map_1.clear = clear;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function keys(map) {
|
||||||
|
var keys = [];
|
||||||
|
map.iterate(function (value, key) {
|
||||||
|
keys.push(key);
|
||||||
|
});
|
||||||
|
return keys;
|
||||||
|
}
|
||||||
|
map_1.keys = keys;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function values(map) {
|
||||||
|
var values = [];
|
||||||
|
map.iterate(function (value, key) {
|
||||||
|
values.push(value);
|
||||||
|
});
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
map_1.values = values;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function dump(map) {
|
||||||
|
var pairs = [];
|
||||||
|
map.iterate(function (value, key) {
|
||||||
|
pairs.push({ "key": key, "value": value });
|
||||||
|
});
|
||||||
|
return pairs;
|
||||||
|
}
|
||||||
|
map_1.dump = dump;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function show(map, options) {
|
||||||
|
if (options === void 0) { options = {}; }
|
||||||
|
options = Object.assign({
|
||||||
|
"show_key": instance_show,
|
||||||
|
"show_value": instance_show
|
||||||
|
}, options);
|
||||||
|
return ("["
|
||||||
|
+
|
||||||
|
(dump(map)
|
||||||
|
.map(function (_a) {
|
||||||
|
var key = _a["key"], value = _a["value"];
|
||||||
|
return (options.show_key(key)
|
||||||
|
+
|
||||||
|
" -> "
|
||||||
|
+
|
||||||
|
options.show_value(value));
|
||||||
|
})
|
||||||
|
.join(", "))
|
||||||
|
+
|
||||||
|
"]");
|
||||||
|
}
|
||||||
|
map_1.show = show;
|
||||||
|
})(map = lib_plankton.map || (lib_plankton.map = {}));
|
||||||
|
})(lib_plankton || (lib_plankton = {}));
|
||||||
|
/*
|
||||||
|
This file is part of »bacterio-plankton:map«.
|
||||||
|
|
||||||
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
||||||
|
<info@greenscale.de>
|
||||||
|
|
||||||
|
»bacterio-plankton:map« is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
»bacterio-plankton:map« is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with »bacterio-plankton:map«. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
var lib_plankton;
|
||||||
|
(function (lib_plankton) {
|
||||||
|
var map;
|
||||||
|
(function (map) {
|
||||||
|
var simplemap;
|
||||||
|
(function (simplemap) {
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function make(options) {
|
||||||
|
if (options === void 0) { options = {}; }
|
||||||
|
options = Object.assign({
|
||||||
|
"data": {}
|
||||||
|
}, options);
|
||||||
|
return {
|
||||||
|
"data": options.data
|
||||||
|
};
|
||||||
|
}
|
||||||
|
simplemap.make = make;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function size(subject) {
|
||||||
|
return Object.keys(subject.data).length;
|
||||||
|
}
|
||||||
|
simplemap.size = size;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function has(subject, key) {
|
||||||
|
return (key in subject.data);
|
||||||
|
}
|
||||||
|
simplemap.has = has;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function get_safe(subject, key) {
|
||||||
|
if (key in subject.data) {
|
||||||
|
return lib_plankton.pod.make_filled(subject.data[key]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return lib_plankton.pod.make_empty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
simplemap.get_safe = get_safe;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function get(subject, key, fallback) {
|
||||||
|
if (fallback === void 0) { fallback = lib_plankton.pod.make_empty(); }
|
||||||
|
if (key in subject.data) {
|
||||||
|
return subject.data[key];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (!lib_plankton.pod.is_filled(fallback)) {
|
||||||
|
throw (new Error("key not found"));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return lib_plankton.pod.cull(fallback);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
simplemap.get = get;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function set(subject, key, value) {
|
||||||
|
subject.data[key] = value;
|
||||||
|
}
|
||||||
|
simplemap.set = set;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function delete_(subject, key) {
|
||||||
|
delete subject.data[key];
|
||||||
|
}
|
||||||
|
simplemap.delete_ = delete_;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function iterate(subject, procedure) {
|
||||||
|
Object.entries(subject.data).forEach(function (_a) {
|
||||||
|
var key = _a[0], value = _a[1];
|
||||||
|
procedure(value, key);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
simplemap.iterate = iterate;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function implementation_map(subject) {
|
||||||
|
return {
|
||||||
|
"size": function () { return size(subject); },
|
||||||
|
"has": function (key) { return has(subject, key); },
|
||||||
|
"get": function (key, fallback) { return get(subject, key, fallback); },
|
||||||
|
"set": function (key, value) { return set(subject, key, value); },
|
||||||
|
"delete": function (key) { return delete_(subject, key); },
|
||||||
|
"iterate": function (function_) { return iterate(subject, function_); }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
simplemap.implementation_map = implementation_map;
|
||||||
|
})(simplemap = map.simplemap || (map.simplemap = {}));
|
||||||
|
})(map = lib_plankton.map || (lib_plankton.map = {}));
|
||||||
|
})(lib_plankton || (lib_plankton = {}));
|
||||||
|
/*
|
||||||
|
This file is part of »bacterio-plankton:map«.
|
||||||
|
|
||||||
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
||||||
|
<info@greenscale.de>
|
||||||
|
|
||||||
|
»bacterio-plankton:map« is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
»bacterio-plankton:map« is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with »bacterio-plankton:map«. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
var lib_plankton;
|
||||||
|
(function (lib_plankton) {
|
||||||
|
var map;
|
||||||
|
(function (map) {
|
||||||
|
var hashmap;
|
||||||
|
(function (hashmap) {
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function make(hashing, options) {
|
||||||
|
if (options === void 0) { options = {}; }
|
||||||
|
options = Object.assign({
|
||||||
|
"pairs": []
|
||||||
|
}, options);
|
||||||
|
var subject = {
|
||||||
|
"hashing": hashing,
|
||||||
|
"core": lib_plankton.map.simplemap.make({})
|
||||||
|
};
|
||||||
|
options.pairs.forEach(function (pair) {
|
||||||
|
set(subject, pair.key, pair.value);
|
||||||
|
});
|
||||||
|
return subject;
|
||||||
|
}
|
||||||
|
hashmap.make = make;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function size(subject) {
|
||||||
|
return lib_plankton.map.simplemap.size(subject.core);
|
||||||
|
}
|
||||||
|
hashmap.size = size;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function has(subject, key) {
|
||||||
|
return lib_plankton.map.simplemap.has(subject.core, subject.hashing(key));
|
||||||
|
}
|
||||||
|
hashmap.has = has;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function get(subject, key, fallback) {
|
||||||
|
if (fallback === void 0) { fallback = lib_plankton.pod.make_empty(); }
|
||||||
|
/*
|
||||||
|
we have to adjust the fallback argument, so that it can be used in our underlying simplemap core
|
||||||
|
therefore we pack the value together with any key as dummy
|
||||||
|
*/
|
||||||
|
return (lib_plankton.map.simplemap.get(subject.core, subject.hashing(key), lib_plankton.pod.propagate(fallback, function (value) { return ({
|
||||||
|
"key": key,
|
||||||
|
"value": value
|
||||||
|
}); }))
|
||||||
|
.value);
|
||||||
|
}
|
||||||
|
hashmap.get = get;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function set(subject, key, value) {
|
||||||
|
var key_ = subject.hashing(key);
|
||||||
|
return (lib_plankton.map.simplemap.set(subject.core, key_, { "key": key, "value": value }));
|
||||||
|
}
|
||||||
|
hashmap.set = set;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function delete_(subject, key) {
|
||||||
|
return (lib_plankton.map.simplemap.delete_(subject.core, subject.hashing(key)));
|
||||||
|
}
|
||||||
|
hashmap.delete_ = delete_;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function iterate(subject, procedure) {
|
||||||
|
return (lib_plankton.map.simplemap.iterate(subject.core, function (_a, key_) {
|
||||||
|
var key = _a["key"], value = _a["value"];
|
||||||
|
procedure(value, key);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
hashmap.iterate = iterate;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function implementation_map(subject) {
|
||||||
|
return {
|
||||||
|
"size": function () { return size(subject); },
|
||||||
|
"has": function (key) { return has(subject, key); },
|
||||||
|
"get": function (key, fallback) { return get(subject, key, fallback); },
|
||||||
|
"set": function (key, value) { return set(subject, key, value); },
|
||||||
|
"delete": function (key) { return delete_(subject, key); },
|
||||||
|
"iterate": function (procedure) { return iterate(subject, procedure); }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
hashmap.implementation_map = implementation_map;
|
||||||
|
})(hashmap = map.hashmap || (map.hashmap = {}));
|
||||||
|
})(map = lib_plankton.map || (lib_plankton.map = {}));
|
||||||
|
})(lib_plankton || (lib_plankton = {}));
|
||||||
|
/*
|
||||||
|
This file is part of »bacterio-plankton:map«.
|
||||||
|
|
||||||
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
||||||
|
<info@greenscale.de>
|
||||||
|
|
||||||
|
»bacterio-plankton:map« is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
»bacterio-plankton:map« is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
3GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with »bacterio-plankton:map«. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
var lib_plankton;
|
||||||
|
(function (lib_plankton) {
|
||||||
|
var map;
|
||||||
|
(function (map) {
|
||||||
|
var collatemap;
|
||||||
|
(function (collatemap) {
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function make(collation, options) {
|
||||||
|
if (options === void 0) { options = {}; }
|
||||||
|
options = Object.assign({
|
||||||
|
"pairs": []
|
||||||
|
}, options);
|
||||||
|
var subject = {
|
||||||
|
"collation": collation,
|
||||||
|
"pairs": []
|
||||||
|
};
|
||||||
|
options.pairs.forEach(function (pair) {
|
||||||
|
set(subject, pair.key, pair.value);
|
||||||
|
});
|
||||||
|
return subject;
|
||||||
|
}
|
||||||
|
collatemap.make = make;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function size(subject) {
|
||||||
|
return subject.pairs.length;
|
||||||
|
}
|
||||||
|
collatemap.size = size;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function has(subject, key) {
|
||||||
|
return (subject.pairs.some(function (pair) { return subject.collation(key, pair.key); }));
|
||||||
|
}
|
||||||
|
collatemap.has = has;
|
||||||
|
/**
|
||||||
|
* @todo use .find
|
||||||
|
*/
|
||||||
|
function get(subject, key, fallback) {
|
||||||
|
var value;
|
||||||
|
var found = (subject.pairs
|
||||||
|
.some(function (pair) {
|
||||||
|
if (subject.collation(key, pair.key)) {
|
||||||
|
value = pair.value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
if (found) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (!lib_plankton.pod.is_filled(fallback)) {
|
||||||
|
throw (new Error("key not found"));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return lib_plankton.pod.cull(fallback);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
collatemap.get = get;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function set(subject, key, value) {
|
||||||
|
var found = (subject.pairs
|
||||||
|
.some(function (pair) {
|
||||||
|
if (subject.collation(key, pair.key)) {
|
||||||
|
// pair.value = value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
if (found) {
|
||||||
|
// nothing
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
subject.pairs.push({
|
||||||
|
"key": key,
|
||||||
|
"value": value
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
collatemap.set = set;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function delete_(subject, key) {
|
||||||
|
var index;
|
||||||
|
var found = (subject.pairs
|
||||||
|
.some(function (pair, index_) {
|
||||||
|
if (subject.collation(key, pair.key)) {
|
||||||
|
index = index_;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
if (found) {
|
||||||
|
subject.pairs.splice(index, 1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
collatemap.delete_ = delete_;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function iterate(subject, function_) {
|
||||||
|
subject.pairs
|
||||||
|
.forEach(function (pair) {
|
||||||
|
function_(pair.value, pair.key);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
collatemap.iterate = iterate;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function implementation_map(subject) {
|
||||||
|
return {
|
||||||
|
"size": function () { return size(subject); },
|
||||||
|
"has": function (key) { return has(subject, key); },
|
||||||
|
"get": function (key, fallback) { return get(subject, key, fallback); },
|
||||||
|
"set": function (key, value) { return set(subject, key, value); },
|
||||||
|
"delete": function (key) { return delete_(subject, key); },
|
||||||
|
"iterate": function (function_) { return iterate(subject, function_); }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
collatemap.implementation_map = implementation_map;
|
||||||
|
})(collatemap = map.collatemap || (map.collatemap = {}));
|
||||||
|
})(map = lib_plankton.map || (lib_plankton.map = {}));
|
||||||
|
})(lib_plankton || (lib_plankton = {}));
|
||||||
|
/*
|
||||||
This file is part of »bacterio-plankton:base64«.
|
This file is part of »bacterio-plankton:base64«.
|
||||||
|
|
||||||
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
||||||
|
|
|
@ -24,6 +24,7 @@ modules="${modules} rest"
|
||||||
modules="${modules} server"
|
modules="${modules} server"
|
||||||
modules="${modules} args"
|
modules="${modules} args"
|
||||||
modules="${modules} bcrypt"
|
modules="${modules} bcrypt"
|
||||||
|
modules="${modules} map"
|
||||||
modules="${modules} auth"
|
modules="${modules} auth"
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue