A.4.9 String Hashing
Static Semantics
{
AI95-00302-03}
The library function Strings.Hash has the following declaration:
with Ada.Containers;
function Ada.Strings.Hash (Key : String)
return Containers.Hash_Type;
pragma Pure(Hash);
Returns an implementation-defined
value which is a function of the value of Key. If A and B
are strings such that A equals B, Hash(A) equals
Hash(B).
Implementation defined: The values returned
by Strings.Hash.
{
AI95-00302-03}
The library function Strings.Fixed.Hash has the following declaration:
with Ada.Containers, Ada.Strings.Hash;
function Ada.Strings.Fixed.Hash (Key : String) return Containers.Hash_Type
renames Ada.Strings.Hash;
pragma Pure(Hash);
{
AI95-00302-03}
The generic library function Strings.Bounded.Hash has the following declaration:
with Ada.Containers;
generic
with package Bounded
is
new Ada.Strings.Bounded.Generic_Bounded_Length (<>);
function Ada.Strings.Bounded.Hash (Key : Bounded.Bounded_String)
return Containers.Hash_Type;
pragma Preelaborate(Hash);
Strings.Bounded.Hash
is equivalent to the function call Strings.Hash (Bounded.To_String (Key));
{
AI95-00302-03}
The library function Strings.Unbounded.Hash has the following declaration:
with Ada.Containers;
function Ada.Strings.Unbounded.Hash (Key : Unbounded_String)
return Containers.Hash_Type;
pragma Preelaborate(Hash);
Strings.Unbounded.Hash
is equivalent to the function call Strings.Hash (To_String (Key));
Implementation Advice
{
AI95-00302-03}
The Hash functions should be good hash functions, returning a wide spread
of values for different string values. It should be unlikely for similar
strings to return the same value.
Implementation Advice: Strings.Hash should
be good a hash function, returning a wide spread of values for different
string values, and similar strings should rarely return the same value.
Ramification: The other functions are
defined in terms of Strings.Hash, so they don't need separate advice
in the Annex.
Extensions to Ada 95
{
AI95-00302-03}
{
extensions to Ada 95}
The Strings.Hash, Strings.Fixed.Hash,
Strings.Bounded.Hash, and Strings.Unbounded.Hash functions are new.