File: hash_table_size.e

package info (click to toggle)
smarteiffel 1.1-11
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 12,288 kB
  • ctags: 40,785
  • sloc: ansic: 35,791; lisp: 4,036; sh: 1,783; java: 895; ruby: 613; python: 209; makefile: 115; csh: 78; cpp: 50
file content (90 lines) | stat: -rw-r--r-- 2,780 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
-- This  file  is  free software,  which comes along with SmartEiffel.  This
-- software is distributed in the hope that it will be useful,  but  WITHOUT
-- ANY  WARRANTY;  without  even the  implied warranty of MERCHANTABILITY or
-- FITNESS FOR A PARTICULAR PURPOSE. You can modify it as you want, provided
-- this header is kept unaltered, and a notification of the changes is added.
-- You  are  allowed  to  redistribute it and sell it, alone or as a part of
-- another product.
--
-- Copyright(C) 1994-2002: INRIA - LORIA (INRIA Lorraine) - ESIAL U.H.P.
--			   - University of Nancy 1 - FRANCE
-- Copyright(C) 2003:      INRIA - LORIA (INRIA Lorraine) - I.U.T. Charlemagne
--			   - University of Nancy 2 - FRANCE
--
--		 Dominique COLNET, Suzanne COLLIN, Olivier ZENDRA,
--			   Philippe RIBET, Cyril ADRIAN
--
-- http://SmartEiffel.loria.fr - SmartEiffel@loria.fr
--
expanded class HASH_TABLE_SIZE
--
-- Some useful features to deal with prime INTEGER values in order to
-- select an appropriate size for some hash table (used for example
-- by the DICTIONARY class as well as by the SET class).
--

feature

   prime_number_ceiling(integer: INTEGER): INTEGER is
         -- A good prime number, large enough, and no smaller than `integer'.
      do
	 if integer <= 53 then
	    -- This seems to be a good minimum value to start hashing with.
	    Result := 53
	 elseif integer <= 97 then
	    Result := 97
	 elseif integer <= 193 then
	    Result := 193
	 elseif integer <= 389 then
	    Result := 389
	 elseif integer <= 769 then
	    Result := 769
	 elseif integer <= 1543 then
	    Result := 1543
	 elseif integer <= 3079 then
	    Result := 3079
	 elseif integer <= 6151 then
	    Result := 6151
	 elseif integer <= 12289 then
	    Result := 12289
	 elseif integer <= 24593 then
	    Result := 24593
	 elseif integer <= 49157 then
	    Result := 49157
	 elseif integer <= 98317 then
	    Result := 98317
	 elseif integer <= 196613 then
	    Result := 196613
	 elseif integer <= 393241 then
	    Result := 393241
	 elseif integer <= 786433 then
	    Result := 786433
	 elseif integer <= 1572869 then
	    Result := 1572869
	 elseif integer <= 3145739 then
	    Result := 3145739
	 elseif integer <= 6291469 then
	    Result := 6291469
	 elseif integer <= 12582917 then
	    Result := 12582917
	 elseif integer <= 25165843 then
	    Result := 25165843
	 elseif integer <= 50331653 then
	    Result := 50331653
	 elseif integer <= 100663319 then
	    Result := 100663319
	 elseif integer <= 201326611 then
	    Result := 201326611
	 elseif integer <= 402653189 then
	    Result := 402653189
	 elseif integer <= 805306457 then
	    Result := 805306457
	 else
	    Result := 1610612741
	    -- This should be enough !
	 end
      ensure
	 Result >= integer
      end

end