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