Module sort [preloaded]

The predicate sort/2 will sort a list by using a set data structure and a comparison among ele-ments. The default implementation use a tree data structure and ISO Prolog lexical compari-son for its sorting. The predicate sort/3 allows specifying other comparisons or a hash data structure. The hash data structure will preserve the input order.

Examples:
?- sort([2,1,3,1], X).
X = [1,2,3]
?- sort([2, 1, 3, 1], X, [type(hash)]).
X = [2, 1, 3]

The predicate keysort/2 will key sort an association list by using a map data structure and a comparison among keys. For duplicate keys, the values will retain their input order. Again, the predicate keysort/3 allows specifying further sort options. The hash data structure will further preserve the input order of the keys.

Examples:
?- hash_code(f, R).
R = 102
?- sys_hash_code(f(X), 1, R).
R = 102

The hash code that is the basis for the hash data type can be queried by the predicates hash_code/2. The hash code is recursively computed along the structure of the given term. Reference data types can implement their own Java hashCode() method. The predicates sys_ground/2 and sys_hash_code/3 provide limited depth versions.

The following set predicates are provided:

sort(L, R): [TC2 8.4.3]
sort(L, R, O):
The predicate sorts the list L and unifies the result with R. The ternary predicate takes additional sort options as argument.
keysort(L, R): [TC2 8.4.4]
keysort(L, R, O):
The predicate key-sorts the association list L and unifies the result with R. The ternary predicate takes additional sort options as argument.
hash_code(T, H):
The predicate succeeds when H unifies with the hash code of T. The term T need not be ground. The hash will be in the range from -2147483648 to 2147483647.
sys_ground(T, H):
The predicate succeeds when T is ground up to depth D.
sys_hash_code(T, D, H):
The predicate succeeds in H with hash code of T up to depth D. The term T need not be ground up to depth D. The hash will be in the range from -2147483648 to 2147483647.

Comments