# Path: taglexicon.py
# def hash32trans(s):
#     return fasthash.hashlongs32(tuple(ord(c) for c in s))
# 
# def hash64trans(s):
#     return fasthash.hashlongs64(tuple(ord(c) for c in s))
# 
# Path: form.py
# class Lookup(Form):
#     def __init__(self, parent, wclexicon):
#         self.parent = parent
#         self.wclexicon = wclexicon
# 
#     def get_wclexicon(self):
#         return self.wclexicon


from math import ceil, log2
from taglexicon import hash32trans, hash64trans
from fasthash import hash32, hash64
from form import Lookup
                  else (lambda s: hash64(1, s.encode('utf-8')))
        for key, value in self.items:
            key_hash = fun(key)
            i = key_hash % size
            while not table[i] is None:
                if table[i][0] == key_hash: break
                i = (i + 1) % size
            if table[i] is None:
                table[i] = (key_hash, value+1)
        return table

    def lookup(self, form):
        if 'normalize' in form.get_translations():
            self.lower = True
        return Lookup(form, self)

    @staticmethod
    def from_file(name, filename, config):
        with open(filename, 'r', encoding='utf-8') as f:
            items = [tuple(line.rstrip('\n').split('\t')) for line in f]
            assert all(len(t) == 2 for t in items)
        return WCLexicon(name, [(key, int(s)) for key, s in items], config)

    def c_emit(self, f):
        table = self.make_table()

        f.write('#define %s 0x%x\n\n' % (
            self.c_size, len(table)))

        def c_kv(entry):

# Path: taglexicon.py
# def hash32trans(s):
#     return fasthash.hashlongs32(tuple(ord(c) for c in s))
# 
# def hash64trans(s):
#     return fasthash.hashlongs64(tuple(ord(c) for c in s))
# 
# Path: form.py
# class Lookup(Form):
#     def __init__(self, parent, wclexicon):
#         self.parent = parent
#         self.wclexicon = wclexicon
# 
#     def get_wclexicon(self):
#         return self.wclexicon


# Path: wclexicon.py
from math import ceil, log2
from taglexicon import hash32trans, hash64trans
from fasthash import hash32, hash64
from form import Lookup

                  else (lambda s: hash64(1, s.encode('utf-8')))
        for key, value in self.items:
            key_hash = fun(key)
            i = key_hash % size
            while not table[i] is None:
                if table[i][0] == key_hash: break
                i = (i + 1) % size
            if table[i] is None:
                table[i] = (key_hash, value+1)
        return table

    def lookup(self, form):
        if 'normalize' in form.get_translations():
            self.lower = True
        return Lookup(form, self)

    @staticmethod
    def from_file(name, filename, config):
        with open(filename, 'r', encoding='utf-8') as f:
            items = [tuple(line.rstrip('\n').split('\t')) for line in f]
            assert all(len(t) == 2 for t in items)
        return WCLexicon(name, [(key, int(s)) for key, s in items], config)

    def c_emit(self, f):
        table = self.make_table()

        f.write('#define %s 0x%x\n\n' % (
            self.c_size, len(table)))

        def c_kv(entry):

            if entry is None: return '{ 0, 0 }'