示例#1
0
    def test_large(self):
        d = Dict()

        for x in range(60000):
            d[str(x)] = x

        # Test key and value
        self.assertEqual(hash27("".join(d)), -35326655653467556)
        self.assertEqual(hash27("".join([str(x) for x in d.values()])),
                         -35326655653467556)
示例#2
0
    def test_small(self):
        d = Dict()

        for x in range(15):
            d[str(x)] = x

        # Test key and value
        self.assertEqual(hash27("".join(d)), 6636034109572507556)
        self.assertEqual(hash27("".join([str(x) for x in d.values()])),
                         6636034109572507556)
示例#3
0
def to_hash(in_str):
    feas = in_str.split(":")[0]
    arr = in_str.split(":")[1]
    out_str = "%s:%s" % (feas, (arr + arr[::-1] + arr[::-2] + arr[::-3]))
    hash_id = hash27(out_str) % dict_size
    if hash_id in hash_dict and hash_dict[hash_id] != out_str:
        print(hash_id, out_str, hash27(out_str))
        print("conflict")
        exit(-1)

    return "%s:%s" % (feas, hash_id)
示例#4
0
文件: testset.py 项目: neuml/py27hash
    def test_large(self):
        d = Set()

        for x in range(60000):
            d.add(str(x))

        self.assertEqual(hash27("".join(d)), -35326655653467556)
示例#5
0
文件: testset.py 项目: neuml/py27hash
    def test_small(self):
        d = Set()

        for x in range(15):
            d.add(str(x))

        self.assertEqual(hash27("".join(d)), 6636034109572507556)
示例#6
0
    def test_merge(self):
        # Build list of (key, value) pairs to preserve insertion ordering
        d = []
        e = []

        for x in range(200):
            d.append((str(x), x))

        for x in range(200):
            e.append((str(x), x))

        m = Dict(d)
        m.update(e)

        self.assertEqual(hash27("".join(m)), -5846033856052761336)
        self.assertEqual(hash27("".join([str(x) for x in m.values()])),
                         -5846033856052761336)
示例#7
0
    def test_keys(self):
        d = Dict()
        d[("abc", 1)] = 1
        d[3.3] = 2
        d[30] = 3
        d["test1234"] = 4

        self.assertEqual(hash27("".join([str(k) for k in d])),
                         7766555225202364718)
示例#8
0
文件: testset.py 项目: neuml/py27hash
    def test_values(self):
        d = Set()
        d.add(("abc", 1))
        d.add(3.3)
        d.add(30)
        d.add("test1234")

        self.assertEqual(hash27("".join([str(k) for k in d])),
                         7766555225202364718)
示例#9
0
    def test_popitem(self):
        d = Dict()

        for x in range(500):
            d[str(x)] = x

        d.popitem()

        self.assertEqual(hash27("".join(d)), -434207861779954688)
示例#10
0
文件: testset.py 项目: neuml/py27hash
    def test_copy(self):
        d = Set()

        for x in range(500):
            d.add(str(x))

        d = d.copy()

        self.assertEqual(hash27("".join(d)), 1141231293364439680)
示例#11
0
    def test_fromkeys(self):
        s = []

        for x in range(500):
            s.append(str(x))

        d = Dict.fromkeys(s)

        self.assertEqual(hash27("".join(d)), -7925872281736336380)
示例#12
0
    def test_copy(self):
        d = Dict()

        for x in range(500):
            d[str(x)] = x

        d = d.copy()

        self.assertEqual(hash27("".join(d)), 1141231293364439680)
示例#13
0
文件: testset.py 项目: neuml/py27hash
    def test_pop(self):
        d = Set()

        for x in range(500):
            d.add(str(x))

        d.pop()

        self.assertEqual(hash27("".join(d)), -434207861779954688)
示例#14
0
文件: parse.py 项目: zhoucc/PaddleRec
def to_hash(feas, arr):
    out_str = "%s:%s" % (feas, (arr + arr[::-1] + arr[::-2] + arr[::-3]))
    hash_id = hash27(out_str) % dict_size
    if hash_id in hash_dict and hash_dict[hash_id] != out_str:
        print(hash_id, out_str, hash(out_str), hash_dict[hash_id])
        print("conflict")
        exit(-1)
    hash_dict[hash_id] = out_str
    return hash_id
示例#15
0
文件: testset.py 项目: neuml/py27hash
    def test_delete(self):
        d = Set()

        for x in range(500):
            d.add(str(x))

        d.remove("53")
        d.discard("155")

        self.assertEqual(hash27("".join(d)), -8652364590473687932)
示例#16
0
    def test_update(self):
        d = Dict()

        for x in range(500):
            d[str(x)] = x

        d["255"] = "abc"
        d["100"] = "123"

        self.assertEqual(hash27("".join(d)), -7925872281736336380)
示例#17
0
    def test_delete(self):
        d = Dict()

        for x in range(500):
            d[str(x)] = x

        del d["53"]
        d.pop("155")

        self.assertEqual(hash27("".join(d)), -8652364590473687932)
示例#18
0
文件: testset.py 项目: neuml/py27hash
    def test_clear(self):
        d = Set()

        for x in range(500):
            d.add(str(x))

        d.clear()

        for x in range(1000, 1500):
            d.add(str(x))

        self.assertEqual(hash27("".join(d)), -1473514505880218088)
示例#19
0
    def test_clear(self):
        d = Dict()

        for x in range(500):
            d[str(x)] = x

        d.clear()

        for x in range(1000, 1500):
            d[str(x)] = x

        self.assertEqual(hash27("".join(d)), -1473514505880218088)
示例#20
0
文件: testset.py 项目: neuml/py27hash
    def test_pickle(self):
        d = Set()

        for x in range(500):
            d.add(str(x))

        d.remove("300")

        # Pickle and reload object
        data = pickle.dumps(d)
        d = pickle.loads(data)

        self.assertEqual(hash27("".join(d)), 6818550152093286356)
示例#21
0
def process(path):
    user_dict = parse_data(data_path + "/users.dat", user_fea)
    movie_dict = parse_movie_data(data_path + "/movies.dat", movie_fea)

    for line in open(path, encoding='ISO-8859-1'):
        line = line.strip()
        arr = line.split("::")
        userid = arr[0]
        movieid = arr[1]
        out_str = "time:%s\t%s\t%s\tlabel:%s" % (arr[3], user_dict[userid],
                                                 movie_dict[movieid], arr[2])
        log_id = hash27(out_str) % 1000000000
        print("%s\t%s" % (log_id, out_str))
示例#22
0
    def test_pickle(self):
        d = Dict()

        for x in range(500):
            d[str(x)] = x

        del d["300"]

        # Pickle and reload object
        data = pickle.dumps(d)
        d = pickle.loads(data)

        self.assertEqual(hash27("".join(d)), 6818550152093286356)
示例#23
0
def generate_online_data(path):
    user_dict = parse_data(data_path + "/users.dat", user_fea)
    movie_dict = parse_movie_data(data_path + "/movies.dat", movie_fea)

    for line in open(path, encoding='ISO-8859-1'):
        line = line.strip()
        arr = line.split("::")
        userid = arr[0]
        movieid = arr[1]
        label = arr[2]
        out_str = "time:%s\t%s\t%s\tlabel:%s" % ("1", user_dict[userid],
                                                 movie_dict[movieid], label)
        log_id = hash27(out_str) % 1000000000
        res = "%s\t%s" % (log_id, out_str)
        arr = res.strip().split("\t")
        out_str = "logid:%s %s %s %s %s %s %s %s %s %s" % \
                (arr[0], arr[1], to_hash(arr[2]), to_hash(arr[3]), to_hash(arr[4]), to_hash(arr[5]), \
                to_hash(arr[6]), to_hash_list(arr[7]), to_hash_list(arr[8]), arr[9])
        print(out_str)
示例#24
0
 def test_thash1(self):
     self.assertEqual(hash27(("abc", 1)), -6007909421085996277)
示例#25
0
 def test_bhash(self):
     self.assertEqual(hash27("test1234".encode("utf-8")),
                      1724133767363937712)
示例#26
0
 def test_shash(self):
     self.assertEqual(hash27("test1234"), 1724133767363937712)
示例#27
0
 def test_ihash(self):
     self.assertEqual(hash27(15344), 15344)
示例#28
0
 def test_fhash(self):
     self.assertEqual(hash27(1235.333333), 3408413012)
示例#29
0
 def test_thash2(self):
     self.assertEqual(hash27((3.5, 5.83)), 8767369050595774471)