Class: Gap::HashChain

Inherits:
Object
  • Object
show all
Defined in:
lib/gap50/cache/hashchain.rb

Defined Under Namespace

Modules: Package Classes: HashNode

Constant Summary collapse

USAGE =
{}

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ HashChain

Returns a new instance of HashChain.



95
96
97
# File 'lib/gap50/cache/hashchain.rb', line 95

def initialize(hash = {})
    @hashnode = HashNode.new hash
end

Instance Method Details

#[](a) ⇒ Object



105
106
107
# File 'lib/gap50/cache/hashchain.rb', line 105

def [](a)
    @hashnode[a]
end

#[]=(a, b) ⇒ Object



109
110
111
# File 'lib/gap50/cache/hashchain.rb', line 109

def []=(a, b)
    @hashnode[a] = b
end

#append(node = HashNode.new, usage = nil) ⇒ Object



99
100
101
102
103
# File 'lib/gap50/cache/hashchain.rb', line 99

def append(node = HashNode.new, usage = nil)
    node.usagetag = usage if usage
    node.next = @hashnode
    @hashnode = node
end

#delete(a) ⇒ Object



129
130
131
# File 'lib/gap50/cache/hashchain.rb', line 129

def delete(a)
    @hashnode.delete(a)
end

#eachObject



133
134
135
# File 'lib/gap50/cache/hashchain.rb', line 133

def each
    @hashnode.hash.each{|k, v| yield k, v}
end

#fromIO(io) ⇒ Object



137
138
139
140
141
142
143
144
145
146
# File 'lib/gap50/cache/hashchain.rb', line 137

def fromIO(io)
    h = HashNode.new {}
    while lenbuf = io.read(8)
        len, = lenbuf.unpack("Q")
        text = io.read(len)
        hash = Marshal.load Zlib::Inflate.inflate text
        h = HashNode.new hash, h
    end
    @hashnode = h
end

#get(a) ⇒ Object



113
114
115
# File 'lib/gap50/cache/hashchain.rb', line 113

def get(a)
    @hashnode.get a
end

#getone(a) ⇒ Object



117
118
119
# File 'lib/gap50/cache/hashchain.rb', line 117

def getone(a)
    @hashnode.getone a
end

#include?(a) ⇒ Boolean

Returns:

  • (Boolean)


125
126
127
# File 'lib/gap50/cache/hashchain.rb', line 125

def include?(a)
    @hashnode.include?(a)
end

#set(a, b) ⇒ Object



121
122
123
# File 'lib/gap50/cache/hashchain.rb', line 121

def set(a, b)
    @hashnode.set a, b
end

#toIO(io) ⇒ Object



148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/gap50/cache/hashchain.rb', line 148

def toIO(io)
    ret = []
    h = @hashnode
    while h
        ret << h.hash
        h = h.next
    end
    ret.reverse.each{|h|
        text = Zlib::Deflate.deflate(Marshal.dump(h), 9)
        len  = [text.length].pack("Q")
        io.write len
        io.write text
    }
end