Beispiel #1
0
 def __hash__(self):
     # Data objects are used in NearCache as keys.
     # When this method is called on Data objects
     # received from the members, buffer is type
     # of bytes instead of bytearray. Since bytes
     # is an alias of str in Python2, we cannot
     # use murmur hash directly on it. The
     # conversion is necessary only on Python2
     if isinstance(self._buffer, bytearray) or six.PY3:
         return murmur_hash3_x86_32(self._buffer)
     return murmur_hash3_x86_32(bytearray(self._buffer))
Beispiel #2
0
    def hash_code(self):
        """Returns the murmur hash of the internal data.

        Returns:
            int: The murmur hash of the internal data.
        """
        return murmur_hash3_x86_32(self.buffer)
    def hash_code(self):
        """
        Returns the murmur hash of the internal data.

        :return: the murmur hash of the internal data.
        """
        return murmur_hash3_x86_32(self._buffer, DATA_OFFSET, self.data_size())
    def test_hash(self):
        expected = [  # Expected values are from the Java implementation
            #  00000000 -> HEAP_DATA_OVERHEAD
            (b"00000000key-1", 1228513025, 107),
            (b"12345678key-1", 1228513025,
             107),  # Heap data overhead should not matter
            (b"00000000key-2", 1503416236, 105),
            (b"00000000key-3", 1876349747, 218),
            (b"00000000key-4", -914632498, 181),
            (b"00000000key-5", -803210507, 111),
            (b"00000000key-6", -847942313, 115),
            (b"00000000key-7", 1196747334, 223),
            (b"00000000key-8", -1444149994, 208),
            (b"00000000key-9", 1182720020, 140),
            # Test with different lengths
            (b"00000000", -1585187909, 238),
            (b"00000000a", -1686100800, 46),
            (b"00000000ab", 312914265, 50),
            (b"00000000abc", -2068121803, 208),
            (b"00000000abcd", -973615161, 236),
            (b"", -1585187909, 238),
        ]

        for key, mm_hash, partition_id in expected:
            h = murmur_hash3_x86_32(bytearray(key))
            p = hash_to_index(h, 271)
            self.assertEqual(h, mm_hash)
            self.assertEqual(p, partition_id)
    def test_hash(self):
        expected = [
            ("key-1", 1228513025, 107),
            ("key-2", 1503416236, 105),
            ("key-3", 1876349747, 218),
            ("key-4", -914632498, 181),
            ("key-5", -803210507, 111),
            ("key-6", -847942313, 115),
            ("key-7", 1196747334, 223),
            ("key-8", -1444149994, 208),
            ("key-9", 1182720020, 140),
        ]

        for key, hash, partition_id in expected:
            h = murmur_hash3_x86_32(key, 0, len(key))
            p = hash_to_index(h, 271)
            self.assertEqual(h, hash)
            self.assertEqual(p, partition_id)
Beispiel #6
0
    def test_hash(self):
        expected = [
            (b"key-1", 1228513025, 107),
            (b"key-2", 1503416236, 105),
            (b"key-3", 1876349747, 218),
            (b"key-4", -914632498, 181),
            (b"key-5", -803210507, 111),
            (b"key-6", -847942313, 115),
            (b"key-7", 1196747334, 223),
            (b"key-8", -1444149994, 208),
            (b"key-9", 1182720020, 140),
        ]

        for key, hash, partition_id in expected:
            h = murmur_hash3_x86_32(key, 0, len(key))
            p = hash_to_index(h, 271)
            self.assertEqual(h, hash)
            self.assertEqual(p, partition_id)
Beispiel #7
0
 def __hash__(self):
     return murmur_hash3_x86_32(self.buffer)
 def hash_code(self):
     """
     :return: return the murmur mash of the internal data
     """
     return murmur_hash3_x86_32(self._buffer, DATA_OFFSET, self.data_size())