Class: Tarantool16::SchemaSpace::Index

Inherits:
Object
  • Object
show all
Defined in:
lib/tarantool16/schema.rb

Constant Summary collapse

ITERS =
{
  tree:   (ITERATOR_EQ..ITERATOR_GT).freeze,
  hash:   [ITERATOR_ALL, ITERATOR_EQ].freeze,
  bitset: [ITERATOR_ALL, ITERATOR_EQ, ITERATOR_BITS_ALL_SET,
           ITERATOR_BITS_ANY_SET, ITERATOR_BITS_ALL_NOT_SET].freeze,
  rtree:  [ITERATOR_ALL, ITERATOR_EQ, ITERATOR_GT, ITERATOR_GE, ITERATOR_LT, ITERATOR_LE,
           ITERATOR_RTREE_OVERLAPS, ITERATOR_RTREE_NEIGHBOR].freeze
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, pos, type, parts, part_names) ⇒ Index

Returns a new instance of Index.



240
241
242
243
244
245
246
247
248
249
250
251
252
253
# File 'lib/tarantool16/schema.rb', line 240

def initialize(name, pos, type, parts, part_names)
  @name = name
  @pos = pos
  @type = type.downcase.to_sym
  @iters = ITERS[@type] or raise "Unknown index type #{type.inspect}"
  @parts = parts
  @part_names = part_names
  @part_positions = {}
  parts.each_with_index{|p, i| @part_positions[p] = i}
  part_names.each_with_index{|p, i|
    @part_positions[p.to_s] = i
    @part_positions[p.to_sym] = i
  }
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



231
232
233
# File 'lib/tarantool16/schema.rb', line 231

def name
  @name
end

#part_namesObject (readonly)

Returns the value of attribute part_names.



231
232
233
# File 'lib/tarantool16/schema.rb', line 231

def part_names
  @part_names
end

#part_positionsObject (readonly)

Returns the value of attribute part_positions.



231
232
233
# File 'lib/tarantool16/schema.rb', line 231

def part_positions
  @part_positions
end

#partsObject (readonly)

Returns the value of attribute parts.



231
232
233
# File 'lib/tarantool16/schema.rb', line 231

def parts
  @parts
end

#posObject (readonly)

Returns the value of attribute pos.



231
232
233
# File 'lib/tarantool16/schema.rb', line 231

def pos
  @pos
end

#typeObject (readonly)

Returns the value of attribute type.



231
232
233
# File 'lib/tarantool16/schema.rb', line 231

def type
  @type
end

Instance Method Details

#can_iterator?(iter, flds_cnt) ⇒ Boolean

Returns:

  • (Boolean)


255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'lib/tarantool16/schema.rb', line 255

def can_iterator?(iter, flds_cnt)
  @iters.include?(iter) && begin
    if iter == ITERATOR_ALL
      true
    elsif @type == :hash && flds_cnt == @parts.count
      true
    elsif flds_cnt == 1
      true
    else
      false
    end
  end
end

#map_key(key) ⇒ Object



269
270
271
272
273
274
275
276
277
# File 'lib/tarantool16/schema.rb', line 269

def map_key(key)
  return key if key.is_a?(Array) || key.nil?
  res = []
  positions = @part_positions
  key.each_key do |k|
    res[positions[k]] = key[k]
  end
  res
end