Class: Picky::Backends::Backend

Inherits:
Object
  • Object
show all
Defined in:
lib/picky/backends/backend.rb

Direct Known Subclasses

File, Memory, Redis, SQLite

Instance Method Summary collapse

Instance Method Details

#create_configuration(bundle, _ = nil) ⇒ Object

Returns an object that on #initial, #load returns an object that responds to:

object[:key] # => value (a value for this config key)


24
25
26
# File 'lib/picky/backends/backend.rb', line 24

def create_configuration bundle, _ = nil
  json bundle.index_path(:configuration)
end

#create_inverted(bundle, _ = nil) ⇒ Object

Returns an object that on #initial, #load returns an object that responds to:

object[:token] # => [id, id, id, id, id] (an array of ids)


17
18
19
# File 'lib/picky/backends/backend.rb', line 17

def create_inverted bundle, _ = nil
  json bundle.index_path(:inverted)
end

#create_realtime(bundle, _ = nil) ⇒ Object

Returns an object that on #initial, #load returns an object that responds to:

object[id] # => [:sym1, :sym2]


31
32
33
# File 'lib/picky/backends/backend.rb', line 31

def create_realtime bundle, _ = nil
  json bundle.index_path(:realtime)
end

#ids(combinations, _, _) ⇒ Object

Returns the result ids for the allocation.

Sorts the ids by size and & through them in the following order (sizes):

  1. 100_000, 400, 30, 2
  2. 2, 30, 400, 100_000
  3. (100_000 & (400 & (30 & 2))) # => result

Note: Uses a C-optimized intersection routine (in performant.c)

for speed and memory efficiency.

Note: In the memory based version we ignore the amount and offset hints. We cannot use the information to speed up the algorithm, unfortunately.



58
59
60
61
62
63
64
# File 'lib/picky/backends/backend.rb', line 58

def ids combinations, _, _
  # Get the ids for each combination and pass to the optimized C algorithm.
  #
  # Note: It orders the passed arrays by size.
  #
  Performant::Array.memory_efficient_intersect combinations.map { |combination| combination.ids }
end

#to_sObject



68
69
70
# File 'lib/picky/backends/backend.rb', line 68

def to_s
  self.class.name
end