def __load_code_map( file_path ) :
    """
    load code map from a file
    """
    from marshal import loads
    file = open( file_path, "r" )
    byte_stream = file.read()
    file.close()
    entry = loads( byte_stream )
    code_map = CodeMap()
    code_map.entry = entry
    return code_map
def check( code_map_entry ) :
    code_map = CodeMap()
    code_map.entry = code_map_entry
    while( 1 ) :
        code = sys.stdin.readline()[:-1]
        flag = -1
        time_stamp = time.time()
        cache = QueryCache( code_map, code )
        print "query cast", time.time() - time_stamp, "s"
        if cache.vaild() :
            cand = cache.get_cand( 0, 6 )
            for index in range( len( cand ) ) :
                code, pinyin, hanzi, freq = cache.get_prop( index )
                print code, pinyin, hanzi, freq
def create_code_map( result ) :

    code_map = CodeMap()
    
    count = [ 0, len( result ) ]
    for r in result :
        code = r[0]
        node = code_map.add_path( code )
        l = get_data( node )
        if l :
            l.extend( r[1] )
        else :
            l = []
            l.extend( r[1] )
            set_data( node, l )
        count[0] = count[0] + 1
        print "mapping", code, count[0], "/", count[1]

    return code_map