Skip to content
Snippets Groups Projects
Commit 4e27840b authored by Julianne's avatar Julianne
Browse files

get_hash

parent b04d18b8
No related branches found
No related tags found
No related merge requests found
No preview for this file type
...@@ -82,8 +82,6 @@ def construction_mphf(set_kmer, n, gamma=2, nb_niveaux=3): ...@@ -82,8 +82,6 @@ def construction_mphf(set_kmer, n, gamma=2, nb_niveaux=3):
rangs = [] rangs = []
# On initialise le rang maximal par 0 # On initialise le rang maximal par 0
max_rang = 0 max_rang = 0
#
i = 0
# On parcours tous les kmers dans set_kmer # On parcours tous les kmers dans set_kmer
for kmer in set_kmer: for kmer in set_kmer:
# hacher le kmer # hacher le kmer
...@@ -94,9 +92,9 @@ def construction_mphf(set_kmer, n, gamma=2, nb_niveaux=3): ...@@ -94,9 +92,9 @@ def construction_mphf(set_kmer, n, gamma=2, nb_niveaux=3):
index = grand_tableau.index(h2) index = grand_tableau.index(h2)
# récupérer son rang (utiliser la fonction count()) # récupérer son rang (utiliser la fonction count())
c = grand_tableau[0:index].count(-1) c = grand_tableau[0:index].count(-1)
rangs = index - c rang = index - c
# ajouter à la mphf [h, rang] # ajouter à la mphf [h, rang]
mphf.append((h2, rangs)) mphf.append((h2, rang))
# mettre à jour max_rang # mettre à jour max_rang
max_rang += 1 max_rang += 1
...@@ -124,16 +122,21 @@ def get_hash_mphf(mphf, kmer): ...@@ -124,16 +122,21 @@ def get_hash_mphf(mphf, kmer):
int: Hash du k-mer. int: Hash du k-mer.
Examples: Examples:
#>>> set_kmer = {str(i) for i in range(10)} >>> set_kmer = {str(i) for i in range(10)}
#>>> n = 10 >>> n = 10
#>>> mphf = construction_mphf(set_kmer, n) >>> mphf = construction_mphf(set_kmer, n)
#>>> kmer = "5" >>> kmer = "5"
#>>> hash_mphf = get_hash_mphf(mphf, kmer) >>> hash_mphf = get_hash_mphf(mphf, kmer)
#>>> 0 <= hash_mphf < n >>> 0 <= hash_mphf < n
#True True
""" """
pass # TODO modifier h = abs(hash(kmer))
for h_kmer, rang in mphf:
if h == h_kmer:
return rang
return -1
def create_hash_table(set_kmer, n): def create_hash_table(set_kmer, n):
""" for _ in range(len(index)): """ for _ in range(len(index)):
c = grand_tableau.count(-1)chage. c = grand_tableau.count(-1)chage.
...@@ -199,4 +202,14 @@ def compare_taille(n_max, fichier_sortie): ...@@ -199,4 +202,14 @@ def compare_taille(n_max, fichier_sortie):
#compare_taille(10000,"mphf.png") #compare_taille(10000,"mphf.png")
import doctest import doctest
doctest.testmod() doctest.testmod()
\ No newline at end of file
if __name__ == '__main__':
set_kmer = {str(i) for i in range(10)}
mphf = construction_mphf(set_kmer, 10)
print(mphf)
kmer = '5'
print(abs(hash(kmer)))
h= get_hash_mphf(mphf, kmer)
print(h)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment