Skip to content
This repository has been archived by the owner on Jun 11, 2020. It is now read-only.

Commit

Permalink
get_id_hash function
Browse files Browse the repository at this point in the history
  • Loading branch information
Leifur Halldor Asgeirsson committed Nov 2, 2016
1 parent 586dfca commit 9c9f2e2
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,7 @@ ENV/

# Rope project settings
.ropeproject


# PyCharm
.idea/
Empty file added goblin_dse/__init__.py
Empty file.
8 changes: 8 additions & 0 deletions goblin_dse/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import functools
import operator


def get_id_hash(id_dict):
hashes = map(hash, id_dict.items())
id_hash = functools.reduce(operator.xor, hashes, 0)
return id_hash
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
goblin
pytest
pytest-asyncio
pytest-cov
23 changes: 23 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from goblin_dse import utils


def test_get_id_hash():
distinct_ids = (
{"~label": "label1", "community_id": 6335574440, "member_id": 1},
{"~label": "label1", "community_id": 6335574440, "member_id": 2},
{"~label": "label1", "community_id": 8412991644, "member_id": 1},
{"~label": "label2", "community_id": 6335574440, "member_id": 1},
{"~label": "vertex_with_custom_id",
"custom_partition_key_name": "custom_partition_key_value"},
)

same_ids = (
{"~label": "label1", "community_id": 6335574440, "member_id": 1},
{"~label": "label1", "community_id": 6335574440, "member_id": 1},
)

distinct_id_hashes_set = {utils.get_id_hash(val) for val in distinct_ids}
same_ids_hashes_set = {utils.get_id_hash(val) for val in same_ids}

assert len(distinct_id_hashes_set) == len(distinct_ids)
assert len(same_ids_hashes_set) == 1

0 comments on commit 9c9f2e2

Please sign in to comment.