Prolog "hash"
Admin User, created Apr 06. 2025
/**
* Warranty & Liability
* To the extent permitted by applicable law and unless explicitly
* otherwise agreed upon, XLOG Technologies AG makes no warranties
* regarding the provided information. XLOG Technologies AG assumes
* no liability that any problems might be solved with the information
* provided by XLOG Technologies AG.
*
* Rights & License
* All industrial property rights regarding the information - copyright
* and patent rights in particular - are the sole property of XLOG
* Technologies AG. If the company was not the originator of some
* excerpts, XLOG Technologies AG has at least obtained the right to
* reproduce, change and translate the information.
*
* Reproduction is restricted to the whole unaltered document. Reproduction
* of the information is only allowed for non-commercial uses. Selling,
* giving away or letting of the execution of the library is prohibited.
* The library can be distributed as part of your applications and libraries
* for execution provided this comment remains unchanged.
*
* Restrictions
* Only to be distributed with programs that add significant and primary
* functionality to the library. Not to be distributed with additional
* software intended to replace any components of the library.
*
* Trademarks
* Jekejeke is a registered trademark of XLOG Technologies AG.
*/
runner_file(calculate, hash, 'XLOG 1.2 hash').
/* hash_enum(S, T) */
runner_pred(hash_enum, 2, calculate, hash, 'XLOG 1.2.1').
runner_case(hash_enum, 2, calculate, hash, 'XLOG 1.2.1, XLOG 1') :-
hash_pairs(H, [a-9,b-8,a-7]),
findall(P, hash_enum(H, P), [Q|_]),
Q == a-7.
runner_case(hash_enum, 2, calculate, hash, 'XLOG 1.2.1, XLOG 2') :-
hash_pairs(H, [a-9,b-8,a-7]),
findall(P, hash_enum(H, P), [_,Q|_]),
Q == b-8.
runner_case(hash_enum, 2, calculate, hash, 'XLOG 1.2.1, XLOG 3') :-
hash_pairs(H, [a-9,b-8,a-7]),
findall(P, hash_enum(H, P), [_,_]).
/* hash_pairs(S, T) */
runner_pred(hash_pairs, 2, calculate, hash, 'XLOG 1.2.2').
runner_case(hash_pairs, 2, calculate, hash, 'XLOG 1.2.2, XLOG 1') :-
hash_new(H),
hash_pairs(H, X),
X == [].
runner_case(hash_pairs, 2, calculate, hash, 'XLOG 1.2.2, XLOG 2') :-
hash_new(H),
hash_set(H, a, 1),
hash_set(H, b, 2),
hash_pairs(H, X),
X == [a-1, b-2].
runner_case(hash_pairs, 2, calculate, hash, 'XLOG 1.2.2, XLOG 3') :-
hash_pairs(H, [a-9,b-8,a-7]),
hash_current(H, a, Y),
Y == 7,
hash_current(H, b, Z),
Z == 8.
runner_case(hash_pairs, 2, calculate, hash, 'XLOG 1.2.2, XLOG 4') :-
hash_pairs(H, [a-9]),
\+ hash_current(H, b, _).
/* hash_size(S, T) */
runner_pred(hash_size, 2, calculate, hash, 'XLOG 1.2.3').
runner_case(hash_size, 2, calculate, hash, 'XLOG 1.2.3, XLOG 1') :-
hash_pairs(H, []),
hash_size(H, X),
X == 0.
runner_case(hash_size, 2, calculate, hash, 'XLOG 1.2.3, XLOG 2') :-
hash_pairs(H, [a-9,b-8,a-7]),
hash_size(H, X),
X == 2.
runner_case(hash_size, 2, calculate, hash, 'XLOG 1.2.3, XLOG 3') :-
hash_pairs(H, [a-9]),
hash_size(H, X),
X == 1.
/* hash_current(T, K, V) */
runner_pred(hash_current, 3, calculate, hash, 'XLOG 1.2.4').
runner_case(hash_current, 3, calculate, hash, 'XLOG 1.2.4, XLOG 1') :-
hash_pairs(H, [foo-[1,2,3],bar-baz]),
hash_current(H, foo, X),
X == [1, 2, 3].
runner_case(hash_current, 3, calculate, hash, 'XLOG 1.2.4, XLOG 2') :-
hash_pairs(H, [foo-[1,2,3],bar-baz,jack-{b:1,a:2}]),
hash_current(H, bar, X),
X == baz.
runner_case(hash_current, 3, calculate, hash, 'XLOG 1.2.4, XLOG 3') :-
hash_pairs(H, [foo-[1,2,3],bar-baz]),
\+ hash_current(H, jack, _).
runner_case(hash_current, 3, calculate, hash, 'XLOG 1.2.4, XLOG 4') :-
hash_pairs(H, []),
\+ hash_current(H, bar, _).
runner_case(hash_current, 3, calculate, hash, 'XLOG 1.2.4, XLOG 5') :-
hash_pairs(H, [jack-{b:1,a:2}]),
hash_current(H, jack, X),
X == {b:1,a:2}.
/* hash_set(T, K, V) */
runner_pred(hash_set, 3, calculate, hash, 'XLOG 1.2.5').
runner_case(hash_set, 3, calculate, hash, 'XLOG 1.2.5, XLOG 1') :-
hash_pairs(H, [foo-[1,2,3],bar-baz]),
hash_set(H, jack, {b:1,a:2}),
hash_pairs(H, X),
X == [foo-[1, 2, 3], bar-baz, jack-{b:1, a:2}].
runner_case(hash_set, 3, calculate, hash, 'XLOG 1.2.5, XLOG 2') :-
hash_pairs(H, [foo-[1,2,3],bar-baz]),
hash_set(H, bar, [4,5,6]),
hash_pairs(H, X),
X == [foo-[1, 2, 3], bar-[4, 5, 6]].
runner_case(hash_set, 3, calculate, hash, 'XLOG 1.2.5, XLOG 3') :-
hash_pairs(H, []),
hash_set(H, bar, baz),
hash_pairs(H, X),
X == [bar-baz].
runner_case(hash_set, 3, calculate, hash, 'XLOG 1.2.5, XLOG 4') :-
hash_pairs(H, [jack-{b:1,a:2}]),
hash_set(H, jack, jeff),
hash_pairs(H, X),
X == [jack-jeff].
/* hash_add(T, K, V) */
runner_pred(hash_add, 3, calculate, hash, 'XLOG 1.2.6').
runner_case(hash_add, 3, calculate, hash, 'XLOG 1.2.6, XLOG 1') :-
hash_pairs(H, [foo-[1,2,3],bar-baz]),
hash_add(H, jack, {b:1,a:2}),
hash_pairs(H, X),
X == [foo-[1, 2, 3], bar-baz, jack-{b:1, a:2}].
runner_case(hash_add, 3, calculate, hash, 'XLOG 1.2.6, XLOG 2') :-
hash_pairs(H, [foo-[1,2,3],bar-baz]),
\+ hash_add(H, bar, [4,5,6]).
runner_case(hash_add, 3, calculate, hash, 'XLOG 1.2.6, XLOG 3') :-
hash_pairs(H, []),
hash_add(H, bar, baz),
hash_pairs(H, X),
X == [bar-baz].
runner_case(hash_add, 3, calculate, hash, 'XLOG 1.2.6, XLOG 4') :-
hash_pairs(H, [jack-{b:1,a:2}]),
\+ hash_add(H, jack, jeff).
/* hash_add(T, K, V, S) */
runner_pred(hash_add, 4, calculate, hash, 'XLOG 1.2.7').
runner_case(hash_add, 4, calculate, hash, 'XLOG 1.2.7, XLOG 1') :-
hash_pairs(H, [foo-[1,2,3],bar-baz]),
hash_add(H, jack, {b:1,a:2}, H2),
hash_pairs(H2, X),
X == [foo-[1, 2, 3], bar-baz, jack-{b:1, a:2}].
runner_case(hash_add, 4, calculate, hash, 'XLOG 1.2.7, XLOG 2') :-
hash_pairs(H, [foo-[1,2,3],bar-baz]),
\+ hash_add(H, bar, [4,5,6], _).
runner_case(hash_add, 4, calculate, hash, 'XLOG 1.2.7, XLOG 3') :-
hash_pairs(H, []),
hash_add(H, bar, baz, H2),
hash_pairs(H2, X),
X == [bar-baz].
runner_case(hash_add, 4, calculate, hash, 'XLOG 1.2.7, XLOG 4') :-
hash_pairs(H, [jack-{b:1,a:2}]),
\+ hash_add(H, jack, jeff, _).