A.4.9 String Hashing
Static Semantics
1/2
The library function
Strings.Hash has the following declaration:
2/2
with Ada.Containers;
function Ada.Strings.Hash (Key : String)
return Containers.Hash_Type;
pragma Pure(Hash);
3/2
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).
4/2
The library function
Strings.Fixed.Hash has the following declaration:
5/2
with Ada.Containers, Ada.Strings.Hash;
function Ada.Strings.Fixed.Hash (Key : String) return Containers.Hash_Type
renames Ada.Strings.Hash;
pragma Pure(Hash);
6/2
The generic library
function Strings.Bounded.Hash has the following declaration:
7/2
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);
8/3
Equivalent to Strings.Hash
(Bounded.To_String (Key));
9/2
The library function
Strings.Unbounded.Hash has the following declaration:
10/2
with Ada.Containers;
function Ada.Strings.Unbounded.Hash (Key : Unbounded_String)
return Containers.Hash_Type;
pragma Preelaborate(Hash);
11/3
Equivalent to Strings.Hash
(To_String (Key));
12/3
The library function
Strings.Hash_Case_Insensitive has the following declaration:
13/3
with Ada.Containers;
function Ada.Strings.Hash_Case_Insensitive (Key : String)
return Containers.Hash_Type;
pragma Pure(Hash_Case_Insensitive);
14/3
Returns an implementation-defined
value which is a function of the value of Key, converted to lower case.
If A and B are strings such that Strings.Equal_Case_Insensitive (A, B)
(see
A.4.10) is True, then Hash_Case_Insensitive(A)
equals Hash_Case_Insensitive(B).
14.1/3
The library function
Strings.Fixed.Hash_Case_Insensitive has the following declaration:
14.2/3
with Ada.Containers, Ada.Strings.Hash_Case_Insensitive;
function Ada.Strings.Fixed.Hash_Case_Insensitive (Key : String)
return Containers.Hash_Type
renames Ada.Strings.Hash_Case_Insensitive;
pragma Pure(Hash_Case_Insensitive);
14.3/2
The generic library
function Strings.Bounded.Hash_Case_Insensitive has the following declaration:
14.4/3
with Ada.Containers;
generic
with package Bounded
is
new Ada.Strings.Bounded.Generic_Bounded_Length (<>);
function Ada.Strings.Bounded.Hash_Case_Insensitive
(Key : Bounded.Bounded_String)
return Containers.Hash_Type;
pragma Preelaborate(Hash_Case_Insensitive);
14.5/3
Equivalent to Strings.Hash_Case_Insensitive
(Bounded.To_String (Key));
14.6/3
The library function
Strings.Unbounded.Hash_Case_Insensitive has the following declaration:
14.7/3
with Ada.Containers;
function Ada.Strings.Unbounded.Hash_Case_Insensitive
(Key : Unbounded_String)
return Containers.Hash_Type;
pragma Preelaborate(Hash_Case_Insensitive);
14.8/3
Equivalent to Strings.Hash_Case_Insensitive
(To_String (Key));
Implementation Advice
15/2
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.
Ada 2005 and 2012 Editions sponsored in part by Ada-Europe