home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #4 / amigaacscoverdisc1998-041998.iso / utilities / shareware / dev / ppcsmalleiffel / lib_se / id_provider.e < prev    next >
Encoding:
Text File  |  1998-01-16  |  2.9 KB  |  125 lines

  1. --          This file is part of SmallEiffel The GNU Eiffel Compiler.
  2. --          Copyright (C) 1994-98 LORIA - UHP - CRIN - INRIA - FRANCE
  3. --            Dominique COLNET and Suzanne COLLIN - colnet@loria.fr 
  4. --                       http://www.loria.fr/SmallEiffel
  5. -- SmallEiffel is  free  software;  you can  redistribute it and/or modify it 
  6. -- under the terms of the GNU General Public License as published by the Free
  7. -- Software  Foundation;  either  version  2, or (at your option)  any  later 
  8. -- version. SmallEiffel is distributed in the hope that it will be useful,but
  9. -- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. -- or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU General Public License 
  11. -- for  more  details.  You  should  have  received a copy of the GNU General 
  12. -- Public  License  along  with  SmallEiffel;  see the file COPYING.  If not,
  13. -- write to the  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. -- Boston, MA 02111-1307, USA.
  15. --
  16. class ID_PROVIDER
  17.    --
  18.    -- Unique object in charge of some id providing.
  19.    --
  20.  
  21. inherit GLOBALS;
  22.  
  23. creation make
  24.  
  25. feature {NONE}
  26.  
  27.    mem_id: FIXED_ARRAY[INTEGER];
  28.  
  29.    mem_str: FIXED_ARRAY[STRING];
  30.  
  31.    modulus: INTEGER;
  32.  
  33. feature {NONE}
  34.  
  35.    make is
  36.       do
  37.      !!mem_id.with_capacity(1024);
  38.      !!mem_str.with_capacity(1024);
  39.      modulus := 1000;
  40.      add2(Void,0); -- (T0)
  41.      add2(us_general,1);
  42.      add2(us_integer,2);
  43.      add2(us_character,3);
  44.      add2(us_real,4);
  45.      add2(us_double,5);
  46.      add2(us_boolean,6);
  47.      add2(us_string,7);
  48.      add2(us_pointer,8);
  49.      add2(us_native_array_character,9);
  50.      --  Free ID for internal indicators :
  51.      add2(Void,10);
  52.      add2(Void,11);
  53.      add2(Void,12);
  54.      add2(Void,13);
  55.      add2(Void,14);
  56.      add2(Void,15);
  57.      add2(Void,16);
  58.      add2(Void,17);
  59.      add2(Void,18);
  60.      add2(Void,19);
  61.      add2(Void,20);
  62.       end;
  63.  
  64. feature {SMALL_EIFFEL}
  65.  
  66.    max_id: INTEGER is
  67.       local
  68.      i: INTEGER;
  69.       do
  70.      from
  71.         i := mem_id.upper;
  72.      until
  73.         i < 0
  74.      loop
  75.         if mem_id.item(i) > Result then
  76.            Result := mem_id.item(i);
  77.         end;
  78.         i := i - 1;
  79.      end;
  80.       end;
  81.    
  82. feature {BASE_CLASS,RUN_CLASS}
  83.  
  84.    item(str: STRING): INTEGER is
  85.       require
  86.      str = unique_string.item(str)
  87.       local
  88.      index: INTEGER;
  89.       do
  90.      index := mem_str.fast_index_of(str);
  91.      if index <= mem_str.upper then
  92.         Result := mem_id.item(index);
  93. --***     elseif run_control.boost then
  94. --***        Result := mem_id.last + 1;
  95. --***        add2(str,Result);
  96.      else
  97.         if mem_str.upper * 2 > modulus then
  98.            modulus := modulus * 2;
  99.         end;
  100.         Result := str.hash_code \\ modulus;
  101.         if mem_id.fast_has(Result) then
  102.            from
  103.            until
  104.           not mem_id.fast_has(Result)
  105.            loop
  106.           Result := (Result + 13) \\ modulus;
  107.            end;
  108.            add2(str,Result);
  109.         else
  110.            add2(str,Result);
  111.         end;
  112.      end;
  113.       end;
  114.  
  115. feature {NONE}
  116.  
  117.    add2(str: STRING; id: INTEGER) is
  118.       do
  119.      mem_str.add_last(str);
  120.      mem_id.add_last(id);
  121.       end;
  122.    
  123. end -- ID_PROVIDER
  124.  
  125.