Class: Humboldt::BinaryPrefixPartitioner

Inherits:
Object
  • Object
show all
Defined in:
lib/humboldt/prefix_grouping.rb

Direct Known Subclasses

DropBinaryPrefixPartitioner

Instance Method Summary collapse

Constructor Details

#initialize(cutoff_index) ⇒ BinaryPrefixPartitioner

Returns a new instance of BinaryPrefixPartitioner.



8
9
10
# File 'lib/humboldt/prefix_grouping.rb', line 8

def initialize(cutoff_index)
  @cutoff_index = cutoff_index
end

Instance Method Details

#partition(key, value, num_partitions) ⇒ Object



12
13
14
15
16
# File 'lib/humboldt/prefix_grouping.rb', line 12

def partition(key, value, num_partitions)
  length = @cutoff_index > key.length ? key.length : @cutoff_index
  prefix = String.from_java_bytes(key.bytes)[0, length]
  Zlib.crc32(prefix) % num_partitions
end