1. -- 
  2. -- Copyright (c) 2012 Kevin Wellwood 
  3. -- All rights reserved. 
  4. -- 
  5. -- This source code is distributed under the Modified BSD License. For terms and 
  6. -- conditions, see license.txt. 
  7. -- 
  8.  
  9. with Ada.Containers;                    use Ada.Containers; 
  10. with Ada.Strings.Unbounded;             use Ada.Strings.Unbounded; 
  11.  
  12. package Hashed_Strings is 
  13.  
  14.     pragma Preelaborate; 
  15.  
  16.     -- A Hashed_String is built from a fixed string using a case-sensitive hash 
  17.     -- function so that it can quickly be compared to other hashed strings. Note 
  18.     -- that the comparison isn't 100% accurate because hash collisions for 
  19.     -- differing strings are possible. Use a Hashed_String if you have a 
  20.     -- constant, case-sensitive string that needs to be compared with other 
  21.     -- constant strings frequently. 
  22.     type Hashed_String is private; 
  23.  
  24.     -- Returns True if the Hashed_Strings match based on hash comparison. This 
  25.     -- isn't 100% accurate. See the comments for the Hashed_String type. 
  26.     function "="( l, r : Hashed_String ) return Boolean; 
  27.  
  28.     -- Like the '=' operator, this function is based on hash comparison. 
  29.     function "<"( l, r : Hashed_String ) return Boolean; 
  30.  
  31.     -- Returns a string from the concatenation of a Hashed_String with a fixed string. 
  32.     function "&"( l : Hashed_String; r : String ) return String; 
  33.  
  34.     -- Returns a string from the concatenation of a fixed string with a Hashed_String. 
  35.     function "&"( l : String; r : Hashed_String ) return String; 
  36.  
  37.     -- Returns a string from the concatenation of two Hashed_Strings. 
  38.     function "&"( l, r : Hashed_String ) return String; 
  39.  
  40.     -- Returns True if the Hashed_Strings match exactly. This is slower than the 
  41.     -- '=' operator because the string contents will be compared if the hash 
  42.     -- values match. 
  43.     function Equivalent( l, r : Hashed_String ) return Boolean; 
  44.  
  45.     -- Returns the hashed value of the internal string. 
  46.     function Hash( sh : Hashed_String ) return Hash_Type; 
  47.  
  48.     -- Makes a Hashed_String from a fixed string. 
  49.     function To_Hashed_String( str : String ) return Hashed_String; 
  50.  
  51.     -- Returns the Hashed_String's internal string. 
  52.     function To_String( hs : Hashed_String ) return String; 
  53.  
  54. private 
  55.  
  56.     type Hashed_String is 
  57.         record 
  58.             ht  : Hash_Type; 
  59.             str : Unbounded_String; 
  60.         end record; 
  61.  
  62. end Hashed_Strings;