Ada Conformity Assessment Authority      Home Conformity Assessment   Test Suite ARGAda Standard
 
Annotated Ada Reference Manual (Ada 2022)Legal Information
Contents   Index   References   Search   Previous   Next 

A.4.9 String Hashing

Static Semantics

1/2
{AI95-00302-03} The library function Strings.Hash has the following declaration: 
2/5
{AI05-0298-1} {AI12-0414-1} with Ada.Containers;
function Ada.Strings.Hash (Key : String) return Containers.Hash_Type;
   with pragma Pure(Ada.Strings.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). 
3.a/2
Implementation defined: The values returned by Strings.Hash.
4/2
{AI95-00302-03} The library function Strings.Fixed.Hash has the following declaration:
5/3
{AI05-0298-1} with Ada.Containers, Ada.Strings.Hash;
function Ada.Strings.Fixed.Hash (Key : String) return Containers.Hash_Type
   renames Ada.Strings.Hash;
6/2
{AI95-00302-03} The generic library function Strings.Bounded.Hash has the following declaration:
7/5
{AI05-0298-1} {AI12-0241-1} {AI12-0302-1} 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;
   with pragma Preelaborate, Nonblocking, Global => in out synchronized(Ada.Strings.Bounded.Hash);
8/3
{AI05-0001-1} Equivalent to Strings.Hash (Bounded.To_String (Key));
9/2
{AI95-00302-03} The library function Strings.Unbounded.Hash has the following declaration:
10/5
{AI05-0298-1} {AI12-0241-1} {AI12-0302-1} with Ada.Containers;
function Ada.Strings.Unbounded.Hash (Key : Unbounded_String)
   return Containers.Hash_Type;
   with pragma Preelaborate, Nonblocking, Global => in out synchronized(Ada.Strings.Unbounded.Hash);
11/3
{AI05-0001-1} Equivalent to Strings.Hash (To_String (Key));
11.1/3
  {AI05-0001-1} {AI05-0298-1} The library function Strings.Hash_Case_Insensitive has the following declaration:
11.2/5
{AI12-0414-1} with Ada.Containers;
function Ada.Strings.Hash_Case_Insensitive (Key : String)
   return Containers.Hash_Type;
   with pragma Pure(Ada.Strings.Hash_Case_Insensitive);
11.3/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). 
11.4/3
  {AI05-0001-1} {AI05-0298-1} The library function Strings.Fixed.Hash_Case_Insensitive has the following declaration:
11.5/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;
11.6/3
  {AI05-0001-1} {AI05-0298-1} The generic library function Strings.Bounded.Hash_Case_Insensitive has the following declaration:
11.7/5
{AI12-0241-1} {AI12-0302-1} 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;
   with pragma Preelaborate, Nonblocking, Global => in out synchronized(Ada.Strings.Bounded.Hash_Case_Insensitive);
11.8/3
Equivalent to Strings.Hash_Case_Insensitive (Bounded.To_String (Key)); 
11.9/3
  {AI05-0001-1} {AI05-0298-1} The library function Strings.Unbounded.Hash_Case_Insensitive has the following declaration:
11.10/5
{AI12-0241-1} {AI12-0302-1} with Ada.Containers;
function Ada.Strings.Unbounded.Hash_Case_Insensitive
   (Key : Unbounded_String) return Containers.Hash_Type;
   with pragma Preelaborate, Nonblocking, Global => in out synchronized(Ada.Strings.Unbounded.Hash_Case_Insensitive);
11.11/3
Equivalent to Strings.Hash_Case_Insensitive (To_String (Key)); 

Implementation Advice

12/2
{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. 
12.a/2
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.
12.b/2
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

12.c/2
{AI95-00302-03} The Strings.Hash, Strings.Fixed.Hash, Strings.Bounded.Hash, and Strings.Unbounded.Hash functions are new. 

Extensions to Ada 2005

12.d/3
{AI05-0001-1} The Strings.Hash_Case_Insensitive, Strings.Fixed.Hash_Case_Insensitive, Strings.Bounded.Hash_Case_Insensitive, and Strings.Unbounded.Hash_Case_Insensitive functions are new. 

Contents   Index   References   Search   Previous   Next 
Ada-Europe Ada 2005 and 2012 Editions sponsored in part by Ada-Europe