ids : identifiers to hash (super-classes) n : number of required free identifiers idc : This array will be filled with n free identifiers return the size of hashTable to create for theses identifiers (mask + 1)
var ph = new Perfecthashing
var idc = new Array[Int]
assert ph.pnand([3, 7, 10], 1, idc) == 6
assert idc[0] == 4
var idc1 = new Array[Int]
assert ph.pnand([3, 7, 10], 1, idc1) == 6
assert idc1[0] == 6
# Perfect numbering : give new free identifiers
# ids : identifiers to hash (super-classes)
# n : number of required free identifiers
# idc : This array will be filled with n free identifiers
# return the size of hashTable to create for theses identifiers (mask + 1)
#
# var ph = new Perfecthashing
# var idc = new Array[Int]
# assert ph.pnand([3, 7, 10], 1, idc) == 6
# assert idc[0] == 4
# var idc1 = new Array[Int]
# assert ph.pnand([3, 7, 10], 1, idc1) == 6
# assert idc1[0] == 6
fun pnand(ids: Array[Int], n: Int, idc: Array[Int]): Int
do
var mask = phand(ids) -1
var i = 0
while n+ids.length > (1 << mask.number_bits(1)) do
# When there are not enough 1-bits
if mask.getbit(i) == 0 then
mask = mask ^ (1 << i)
end
i += 1
end
# Resetting hashtable
for j in [0..(mask+1)] do tempht[j] = null
# Set the temporary hashtable for `compute_least_free_ids`
phandp(ids, mask)
# Fill the given array with n free identifiers
compute_least_free_ids(n, mask, idc)
return mask + 1
end
lib/perfect_hashing/perfect_hashing.nit:99,2--134,4