Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 29 additions & 29 deletions sources/dylan/table.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,31 @@ define constant $default-table-size = 10;
// Must be a prime number.
define constant $minimum-entries = 31;


define constant $entry-counts =
#[ 2, 3, 5, 7, 11, 13, 17, 19,
23, 29, 31, 37, 41, 47, 53, 59,
67, 71, 79, 83, 89, 97, 103, 109,
127, 137, 149, 157, 167, 179, 191, 211,
223, 239, 251, 269, 283, 307, 331, 349,
367, 389, 409, 431, 457, 487, 521, 557,
587, 617, 653, 691, 727, 769, 809, 853,
907, 953, 1009, 1061, 1117, 1181, 1249, 1319,
1399, 1471, 1549, 1627, 1709, 1801, 1901, 1997,
2099, 2207, 2333, 2459, 2591, 2729, 2879, 3023,
3181, 3343, 3511, 3691, 3877, 4073, 4283, 4507,
4733, 4973, 5227, 5501, 5779, 6073, 6379, 6701,
7039, 7393, 7789, 8179, 8597, 9029, 9491, 9967,
10477, 11003, 11579, 12161, 12781, 13421, 14107, 14813,
15559, 16339, 17159, 18041, 18947, 19913, 20921, 21977,
23081, 24239, 25453, 26729, 28069, 29473, 30949, 32497,
34123, 35831, 37633, 39521, 41507, 43591, 45779, 48073,
50497, 55547, 61121, 67247, 73973, 81371, 89513, 98467,
108343, 119179, 131101, 144223, 158647, 174527, 191999, 211199,
232333, 255571, 281131, 309251, 340183, 374203, 411637, 452807,
498089, 547901, 602711, 662999, 729301, 802253, 882481, 970747,
1067831, 1174619, 1292089, 1421309, 1563449, 1719799, 1891789, 2080979,
2289083, 2518003, 2769841, 3046829, 3351521, 3686677, 4055347, 4460891,
4906991, 5397697, 5937469, 6531221, 7184351, 7902787, 8693071, 9562387];
// Sequence of primes, each greater than its predecessor by a factor
// of at least 1.25. All are less than the maximum positive fixed
// integer on 32-bit platforms.
define constant $entry-counts :: <simple-object-vector> =
#[ 2, 3, 5, 7,
11, 17, 23, 29,
37, 47, 59, 79,
101, 127, 163, 211,
269, 337, 431, 541,
677, 853, 1_069, 1_361,
1_709, 2_137, 2_677, 3_347,
4_201, 5_261, 6_577, 8_231,
10_289, 12_889, 16_127, 20_161,
25_219, 31_531, 39_419, 49_277,
61_603, 77_017, 96_281, 120_371,
150_473, 188_107, 235_159, 293_957,
367_453, 459_317, 574_157, 717_697,
897_133, 1_121_423, 1_401_791, 1_752_239,
2_190_299, 2_737_937, 3_422_429, 4_278_037,
5_347_553, 6_684_443, 8_355_563, 10_444_457,
13_055_587, 16_319_519, 20_399_411, 25_499_291,
31_874_149, 39_842_687, 49_803_361, 62_254_207,
77_817_767, 97_272_239, 121_590_311, 151_987_889,
189_984_863, 237_481_091, 296_851_369, 371_064_217,
463_830_313];

define constant $entry-last :: <integer> = $entry-counts.size - 1;

Expand All @@ -74,10 +73,11 @@ define function search-for-entry-count
// smallest good entry count that is not smaller than the
// needed number of entries.
if (lower = upper)
vector-element($entry-counts, lower);
primitive-the(<integer>, vector-element($entry-counts, lower))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, couldn't this also be achieved by making $entry-counts be a limited(<vector>, of: <integer>)?

@housel housel Jun 24, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, couldn't this also be achieved by making $entry-counts be a limited(<vector>, of: <integer>)?

Not quite as easily, you'd have to initialize it with as(limited(<vector>, of: <integer>), #[...]) which would have an initialization-time cost. I don't think the compiler can do the conversion at compile time (yet).

else
let index = ash(lower + upper, -1);
let elt :: <integer> = vector-element($entry-counts, index);
let elt :: <integer>
= primitive-the(<integer>, vector-element($entry-counts, index));
if (elt < needed)
loop(index + 1, upper);
else
Expand All @@ -98,7 +98,7 @@ define function compute-entry-count (desired :: <integer>)
compute-entry-count(0);
else
let needed = max(ceiling/(desired, $grow-threshold), $minimum-entries);
if (needed <= vector-element($entry-counts, $entry-last))
if (needed <= primitive-the(<integer>, vector-element($entry-counts, $entry-last)))
search-for-entry-count(needed);
else
// Signal some more specific class of error?
Expand Down
Loading