Class: OklahomaMixer::FixedLengthDatabase

Inherits:
HashDatabase show all
Defined in:
lib/oklahoma_mixer/fixed_length_database.rb,
lib/oklahoma_mixer/fixed_length_database/c.rb

Defined Under Namespace

Modules: C

Constant Summary

Constants inherited from HashDatabase

HashDatabase::MODES, HashDatabase::OPTS

Instance Attribute Summary

Attributes inherited from HashDatabase

#path

Instance Method Summary collapse

Methods inherited from HashDatabase

#[], #abort, #clear, #close, #commit, #copy, #default, #default=, #delete, #delete_if, #each_value, #empty?, #fetch, #file_size, #flush, #include?, #initialize, #read_only?, #size, #store, #to_hash, #transaction, #update, #values, #values_at

Constructor Details

This class inherits a constructor from OklahomaMixer::HashDatabase

Instance Method Details

#defrag(steps = 0) ⇒ Object



16
17
18
# File 'lib/oklahoma_mixer/fixed_length_database.rb', line 16

def defrag(steps = 0)
  # do nothing:  not needed, but provided for a consistent interface
end

#eachObject Also known as: each_pair



72
73
74
75
76
# File 'lib/oklahoma_mixer/fixed_length_database.rb', line 72

def each
  each_key do |key|
    yield [key, self[key]]
  end
end

#each_keyObject

Iteration ###



62
63
64
65
66
67
68
69
70
# File 'lib/oklahoma_mixer/fixed_length_database.rb', line 62

def each_key
  try(:iterinit)
  loop do
    return self unless key = try( :iternext,
                                  :failure  => 0,
                                  :no_error => {22 => nil} )
    yield key  # cast not needed:  already Integer
  end
end

#keys(options = { }) ⇒ Object

Getting and Setting Keys ###



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/oklahoma_mixer/fixed_length_database.rb', line 24

def keys(options = { })
  if options.include? :range
    warn "range supersedes prefix" if options[:prefix]
    range = options[:range]
    unless range.respond_to?(:first) and range.respond_to?(:last)
      fail ArgumentError, "Range or two element Array expected"
    end
    start          = cast_key_in(range.first)
    include_start  = !options.fetch(:exclude_start, false)
    finish         = cast_key_in(range.last)
    include_finish = !( range.respond_to?(:exclude_end?) ?
                        range.exclude_end?               :
                        options.fetch(:exclude_end, false) )
  else
    fail ArgumentError, "prefix not supported" if options[:prefix]
    start          = cast_key_in(:min)
    include_start  = true
    finish         = cast_key_in(:max)
    include_finish = true
  end
  limit = options.fetch(:limit, -1)
  Utilities.temp_int do |count|
    begin
      list  = lib.range(@db, start, finish, limit, count)
      array = list.get_array_of_uint64(0, count.get_int(0))
      array.shift if array.first == start  and not include_start
      array.pop   if array.last  == finish and not include_finish
      array  # cast not needed:  already Integer
    ensure
      Utilities.free(list) if list
    end
  end
end

#optimize(options) ⇒ Object

File System ###



10
11
12
13
14
# File 'lib/oklahoma_mixer/fixed_length_database.rb', line 10

def optimize(options)
  try( options[:tune] ? :tune : :optimize,
       options.fetch(:width,  0).to_i,
       options.fetch(:limsiz, 0).to_i  )
end