Repository: barrust/pyprobables

Issue:
Add a function to insert raw `bytes` into a filter.

Discussion:
codecov-commenter: # [Codecov](https://codecov.io/gh/barrust/pyprobables/pull/77?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tyler+Barrus) Report
> Merging [#77](https://codecov.io/gh/barrust/pyprobables/pull/77?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tyler+Barrus) (5510485) into [master](https://codecov.io/gh/barrust/pyprobables/commit/ddf3d8ab3beee39ebc5efb8324077d96a2bc82fc?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tyler+Barrus) (ddf3d8a) will **increase** coverage by `0.00%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/barrust/pyprobables/pull/77/graphs/tree.svg?width=650&height=150&src=pr&token=SGjJODewBP&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tyler+Barrus)](https://codecov.io/gh/barrust/pyprobables/pull/77?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tyler+Barrus)

```diff
@@           Coverage Diff           @@
##           master      #77   +/-   ##
=======================================
  Coverage   99.20%   99.21%           
=======================================
  Files          15       15           
  Lines        1390     1394    +4     
=======================================
+ Hits         1379     1383    +4     
  Misses         11       11           
```


| [Impacted Files](https://codecov.io/gh/barrust/pyprobables/pull/77?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tyler+Barrus) | Coverage Δ | |
|---|---|---|
| [probables/hashes.py](https://codecov.io/gh/barrust/pyprobables/pull/77/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tyler+Barrus#diff-cHJvYmFibGVzL2hhc2hlcy5weQ==) | `100.00% <100.00%> (ø)` | |


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 68d5abf..6007e77 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,10 +1,15 @@
 # PyProbables Changelog
 
+### Future Release
+* Add ability to hash bytes along with strings
+
+
 ### Version 0.5.1
 * Bloom Filter:
     * Export as a C header (**\*.h**)
 * Count-Min Sketch
     * Add join/merge functionality
+* Moved testing to use `NamedTemporaryFile` for file based tests
 
 ### Version 0.5.0
 * ***BACKWARD INCOMPATIBLE CHANGES***
diff --git a/probables/hashes.py b/probables/hashes.py
index 4f1c88c..c90709e 100644
--- a/probables/hashes.py
+++ b/probables/hashes.py
@@ -24,7 +24,9 @@ def hash_with_depth_bytes(func):
     def hashing_func(key, depth=1):
         """ wrapper function """
         res = list()
-        tmp = key.encode("utf-8")
+        tmp = key
+        if isinstance(key, str):
+            tmp = key.encode("utf-8")
         for idx in range(depth):
             tmp = func(tmp, idx)
             res.append(unpack("Q", tmp[:8])[0])  # turn into 64 bit number
@@ -88,7 +90,9 @@ def fnv_1a(key, seed=0):
     max64mod = UINT64_T_MAX + 1
     hval = (14695981039346656037 + (31 * seed)) % max64mod
     fnv_64_prime = 1099511628211
-    tmp = map(ord, key)
+    tmp = key
+    if isinstance(key, str):
+        tmp = map(ord, key)
     for t_str in tmp:
         hval ^= t_str
         hval *= fnv_64_prime


Test patch:
diff --git a/tests/hashes_test.py b/tests/hashes_test.py
index 187fdc5..e99cc42 100644
--- a/tests/hashes_test.py
+++ b/tests/hashes_test.py
@@ -130,3 +130,66 @@ class TestHashes(unittest.TestCase):
         res = my_hash("this is a test", 1)
         self.assertEqual(len(res), 1)
         self.assertEqual(res[0], results[0])
+
+    def test_default_fnv_1a_bytes(self):
+        """ test default fnv-1a algorithm """
+        this_is_a_test = [
+            4040040117721899264,
+            3916497180155386777,
+            468410530588793106,
+            13781401791305604595,
+            321382271269641900,
+        ]
+        this_is_also = [
+            7925790280716546811,
+            13347851945403505568,
+            17775584719969392601,
+            10279404995231728046,
+            13802534855964835503,
+        ]
+        hashes = default_fnv_1a(b"this is a test", 5)
+        self.assertEqual(hashes, this_is_a_test)
+        hashes = default_fnv_1a(b"this is also a test", 5)
+        self.assertEqual(hashes, this_is_also)
+
+    def test_default_md5_bytes(self):
+        """ test default md5 algorithm using bytes """
+        this_is_a_test = [
+            12174049463882854484,
+            10455450501617390806,
+            3838261292881602234,
+            12102952520950148619,
+            12126605867972429202,
+        ]
+        this_is_also = [
+            8938037604889355346,
+            9361632593818981393,
+            15781121455678786382,
+            5600686735535066561,
+            1353473153840687523,
+        ]
+        hashes = default_md5(b"this is a test", 5)
+        self.assertEqual(hashes, this_is_a_test)
+        hashes = default_md5(b"this is also a test", 5)
+        self.assertEqual(hashes, this_is_also)
+
+    def test_default_sha256_bytes(self):
+        """ test default sha256 algorithm using bytes """
+        this_is_a_test = [
+            10244166640140130606,
+            5650905005272240665,
+            14215057275609328422,
+            5952353080197385534,
+            4990779931033217093,
+        ]
+        this_is_also = [
+            4140421647067018332,
+            9306548247555387104,
+            5672713771950536751,
+            8501641957786831066,
+            15146689942378126332,
+        ]
+        hashes = default_sha256(b"this is a test", 5)
+        self.assertEqual(hashes, this_is_a_test)
+        hashes = default_sha256(b"this is also a test", 5)
+        self.assertEqual(hashes, this_is_also)