[ library(hash) | Reference Manual | Alphabetic Index ]

hash_update(+Table, ++Key, -OldValue, +NewValue)

Lookup and replace the value stored under Key
Table
A hash table
Key
a ground term
OldValue
Any term
NewValue
Any term

Description

A combination of hash_get/3 and hash_set/3, but more efficient because there is only one hash lookup.

Modes and Determinism

Fail Conditions

No entry for Key

Examples

	?- hash_create(H),
	   hash_set(H, k, hello),
	   hash_update(H, k, Old, world),
	   hash_get(H, k, New).

	Old = hello
	New = world
	Yes (0.00s cpu)

	% sample code based on hash_update/4:
    	hash_inc(H, Key) :-
	    hash_update(H, Key, N0, N1),
	    N1 is N0+1.

    	hash_addto(H, Key, Value) :-
	    hash_update(H, Key, Values, [Value|Values]).
    

See Also

hash_get / 3, hash_set / 3