Class: Antlr4::Runtime::MurmurHash

Inherits:
Object
  • Object
show all
Defined in:
lib/antlr4/runtime/murmur_hash.rb

Constant Summary collapse

DEFAULT_SEED =
0
MASK_32 =
0xFFFFFFFF

Class Method Summary collapse

Class Method Details

.hash_int(num) ⇒ Object



10
11
12
13
14
# File 'lib/antlr4/runtime/murmur_hash.rb', line 10

def self.hash_int(num)
  hash_code = 7
  hash_code = RumourHash.rumour_hash_update_int(hash_code, num)
  RumourHash.rumour_hash_finish(hash_code, 0)
end

.hash_int_int(num1, num2) ⇒ Object



32
33
34
35
36
37
# File 'lib/antlr4/runtime/murmur_hash.rb', line 32

def self.hash_int_int(num1, num2)
  hash_code = 7
  hash_code = RumourHash.rumour_hash_update_int(hash_code, num1)
  hash_code = RumourHash.rumour_hash_update_int(hash_code, num2)
  RumourHash.rumour_hash_finish(hash_code, 2)
end

.hash_int_int_obj_obj(num1, num2, obj1, obj2) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/antlr4/runtime/murmur_hash.rb', line 23

def self.hash_int_int_obj_obj(num1, num2, obj1, obj2)
  hash_code = 7
  hash_code = RumourHash.rumour_hash_update_int(hash_code, num1)
  hash_code = RumourHash.rumour_hash_update_int(hash_code, num2)
  hash_code = RumourHash.rumour_hash_update_int(hash_code, !obj1.nil? ? obj1.hash : 0)
  hash_code = RumourHash.rumour_hash_update_int(hash_code, !obj2.nil? ? obj2.hash : 0)
  RumourHash.rumour_hash_finish(hash_code, 4)
end

.hash_int_obj(num, obj) ⇒ Object



16
17
18
19
20
21
# File 'lib/antlr4/runtime/murmur_hash.rb', line 16

def self.hash_int_obj(num, obj)
  hash_code = 7
  hash_code = RumourHash.rumour_hash_update_int(hash_code, num)
  hash_code = RumourHash.rumour_hash_update_int(hash_code, !obj.nil? ? obj.hash : 0)
  RumourHash.rumour_hash_finish(hash_code, 2)
end

.hash_ints(nums) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/antlr4/runtime/murmur_hash.rb', line 72

def self.hash_ints(nums)
  hash_code = 7

  i = 0
  while i < nums.length
    num = nums[i]
    hash_code = RumourHash.rumour_hash_update_int(hash_code, num)
    i += 1
  end

  RumourHash.rumour_hash_finish(hash_code, 2 * nums.length)
end

.hash_ints_objs(nums, objs) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/antlr4/runtime/murmur_hash.rb', line 52

def self.hash_ints_objs(nums, objs)
  hash_code = 7

  i = 0
  while i < objs.length
    obj = objs[i]
    hash_code = RumourHash.rumour_hash_update_int(hash_code, !obj.nil? ? obj.hash : 0)
    i += 1
  end

  i = 0
  while i < nums.length
    num = nums[i]
    hash_code = RumourHash.rumour_hash_update_int(hash_code, num)
    i += 1
  end

  RumourHash.rumour_hash_finish(hash_code, 2 * objs.length)
end

.hash_objs(objs) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/antlr4/runtime/murmur_hash.rb', line 39

def self.hash_objs(objs)
  hash_code = 7

  i = 0
  while i < objs.length
    obj = objs[i]
    hash_code = RumourHash.rumour_hash_update_int(hash_code, !obj.nil? ? obj.hash : 0)
    i += 1
  end

  RumourHash.rumour_hash_finish(hash_code, objs.length)
end