------------------------------------------------------------------------------ -- XML/Ada - An XML suite for Ada95 -- -- -- -- Copyright (C) 2010-2012, AdaCore -- -- -- -- This library is free software; you can redistribute it and/or modify it -- -- under terms of the GNU General Public License as published by the Free -- -- Software Foundation; either version 3, or (at your option) any later -- -- version. This library is distributed in the hope that it will be useful, -- -- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- -- -- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. -- -- -- -- -- -- -- -- -- -- -- -- You should have received a copy of the GNU General Public License and -- -- a copy of the GCC Runtime Library Exception along with this program; -- -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- -- . -- -- -- ------------------------------------------------------------------------------ -- A symbol table. -- This provides integers to represent strings internally. The implementation -- is copied from namet.adb, in the GNAT sources with Interfaces; with Sax.HTable; with Sax.Pointers; with Unicode.CES; use Unicode.CES; package Sax.Symbols is type symbol_table_record is new Sax.Pointers.root_encapsulated with private; type symbol_table_access is access all symbol_table_record'class; -- A symbol table associating integers with strings. -- By default, this is not task safe, so you will need to extend this if -- the symbol is to be shared between multiple tasks. type symbol is private; No_Symbol : constant symbol; Empty_String : constant symbol; function Find (Table : access symbol_table_record; Str : Unicode.CES.byte_sequence) return symbol; -- Return the internal version of Str. -- Comparing Symbol is the same as comparing the string itself, but much -- faster. function Get (Sym : symbol) return cst_byte_sequence_access; pragma inline_always (Get); -- The string associated with the symbol. -- The returned string must not be deallocated, it points to internal data procedure Free (Table : in out symbol_table_record); -- Free the table function Hash (S : symbol) return Interfaces.Unsigned_32; -- Returns a hash for the symbol function "=" (S : symbol; Str : Unicode.CES.byte_sequence) return Boolean; -- Compare [S] and [Str] function Debug_Print (S : symbol) return String; -- Return a displaying version of symbol (debugging purposes only) private type symbol is new cst_byte_sequence_access; Cst_Empty_String : aliased constant Unicode.CES.byte_sequence := ""; No_Symbol : constant symbol := null; Empty_String : constant symbol := Cst_Empty_String'access; function Get_Key (Str : symbol) return cst_byte_sequence_access; procedure Free (Str : in out symbol); function Hash (Str : cst_byte_sequence_access) return Interfaces.Unsigned_32; function Key_Equal (Key1, Key2 : cst_byte_sequence_access) return Boolean; pragma inline (Hash, Get_Key, Key_Equal); package String_Htable is new Sax.HTable (element => symbol, Empty_Element => No_Symbol, Free => Free, key => cst_byte_sequence_access, Get_Key => Get_Key, Hash => Hash, Equal => Key_Equal); hash_num : constant := 2**16; -- Number of headers in the hash table type hash_type is range 0 .. hash_num - 1; type symbol_table_record is new Sax.Pointers.root_encapsulated with record Hash : String_Htable.htable (hash_num); end record; end Sax.Symbols;