Module: Persist::PKIAdapter

Includes:
TSVAdapter
Defined in:
lib/rbbt/persist/tsv/packed_index.rb

Constant Summary

Constants included from TSVAdapter

TSVAdapter::MAX_CHAR

Instance Attribute Summary collapse

Attributes included from TSVAdapter

#closed, #mutex, #persistence_path, #writable

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TSVAdapter

#close, #closed?, #collect, #delete, #get_prefix, #lock, #lock_and_close, #merge!, #prefix, #range, #read, #read?, #read_and_close, #read_lock, #size, #values_at, #with_read, #with_write, #write, #write?, #write_and_close, #write_and_read, #write_lock

Instance Attribute Details

#pos_functionObject

Returns the value of attribute pos_function.



8
9
10
# File 'lib/rbbt/persist/tsv/packed_index.rb', line 8

def pos_function
  @pos_function
end

Class Method Details

.open(path, write, pattern, &pos_function) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/rbbt/persist/tsv/packed_index.rb', line 10

def self.open(path, write, pattern, &pos_function)
  db = CONNECTIONS[path] ||= PackedIndex.new(path, write, pattern)
  db.extend Persist::PKIAdapter
  db.persistence_path = path
  db.pos_function = pos_function
  db
end

Instance Method Details

#[](key, clean = false) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/rbbt/persist/tsv/packed_index.rb', line 40

def [](key, clean = false)
  if TSV::ENTRY_KEYS.include? key
    [key]
  else
    key = pos_function.call(key) if pos_function and not clean
    res = super(key)
    res.extend MultipleResult unless res.nil?
    res
  end
end

#[]=(key, value) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/rbbt/persist/tsv/packed_index.rb', line 55

def []=(key, value)
  if TSV::ENTRY_KEYS.include? key
    (key, value)
  else
    add key, value
  end
end

#add(key, value) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/rbbt/persist/tsv/packed_index.rb', line 63

def add(key, value)
  key = pos_function.call(key) if pos_function 
  if Numeric === key
    @_last ||= -1
    skipped = key - @_last - 1
    skipped.times do
      self.send(:<<, nil)
    end
    @_last = key
  end
  self.send(:<<, value)
end

#add_range_point(key, value) ⇒ Object



76
77
78
79
# File 'lib/rbbt/persist/tsv/packed_index.rb', line 76

def add_range_point(key, value)
  key = pos_function.call(key) if pos_function
  super(key, value)
end

#eachObject



87
88
89
90
91
# File 'lib/rbbt/persist/tsv/packed_index.rb', line 87

def each
  size.times do |i|
    yield i, value(i)
  end
end

#include?(i) ⇒ Boolean

Returns:

  • (Boolean)


81
82
83
84
85
# File 'lib/rbbt/persist/tsv/packed_index.rb', line 81

def include?(i)
  return true if Numeric === i and i < size
  return true if .include? i
  false
end

#keysObject



93
94
95
# File 'lib/rbbt/persist/tsv/packed_index.rb', line 93

def keys
  []
end

#metadataObject



27
28
29
30
31
32
# File 'lib/rbbt/persist/tsv/packed_index.rb', line 27

def 
  return {} unless File.exist? 
  Open.open(, :mode => "rb") do |f|
    Marshal.load(f)
  end
end

#metadata_fileObject



23
24
25
# File 'lib/rbbt/persist/tsv/packed_index.rb', line 23

def 
  @metadata_file ||= self.persistence_path + '.metadata'
end

#persistence_path=(value) ⇒ Object



18
19
20
21
# File 'lib/rbbt/persist/tsv/packed_index.rb', line 18

def persistence_path=(value)
  @persistence_path = value
  @file = value
end

#set_metadata(k, v) ⇒ Object



34
35
36
37
38
# File 'lib/rbbt/persist/tsv/packed_index.rb', line 34

def (k,v)
   = self.
  [k] = v
  Misc.sensiblewrite(, Marshal.dump())
end

#value(pos) ⇒ Object



51
52
53
# File 'lib/rbbt/persist/tsv/packed_index.rb', line 51

def value(pos)
  self.send(:[], pos, true)
end