Skip to content
This repository has been archived by the owner on Dec 21, 2017. It is now read-only.

Commit

Permalink
* Fixed bug in MemoryStore where a frozen resource could be returned.
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Jan 7, 2011
1 parent 805f059 commit fd0168d
Showing 1 changed file with 38 additions and 18 deletions.
56 changes: 38 additions & 18 deletions lib/rdf_context/store/memory_store.rb
Expand Up @@ -36,22 +36,7 @@ def formula_aware?; true; end
# @return [MemoryStore]
def initialize(identifier = nil, configuration = {})
super
# indexed by [context][subject][predicate][object] = 1
@cspo = {}
# indexed by [context][predicate][object][subject] = 1
@cpos = {}
# indexed by [context][object][subject][predicate] = 1
@cosp = {}
# indexed by [subject][predicate][object] = [context]
@spo = {}
# indexed by [predicate][object][subject] = [context]
@pos = {}
# indexed by [object][subject][predicate] = [context]
@osp = {}
# indexes integer keys to identifiers
@forward = {}
# reverse index of forward
@reverse = {}
destroy({})
end

def inspect
Expand All @@ -70,6 +55,39 @@ def dump
" reverse: #{@reverse.inspect}\n"
end

# Destroy store or context
# If context is specified remove that context, otherwise, re-initialize the store
#
# @option configuration [Graph] :context Remove the specified context
def destroy(configuration = {})
if ctx = configuration[:context]
remove(Triple.new(nil, nil, nil), ctx)

ci = resource_to_int(ctx)
if ci
@reverse.delete(ctx.hash)
@forward.delete(ci)
end
else
# indexed by [context][subject][predicate][object] = 1
@cspo = {}
# indexed by [context][predicate][object][subject] = 1
@cpos = {}
# indexed by [context][object][subject][predicate] = 1
@cosp = {}
# indexed by [subject][predicate][object] = [context]
@spo = {}
# indexed by [predicate][object][subject] = [context]
@pos = {}
# indexed by [object][subject][predicate] = [context]
@osp = {}
# indexes integer keys to identifiers
@forward = {}
# reverse index of forward
@reverse = {}
end
end

# Add a triple to the store
# Add to default context, if context is nil
#
Expand Down Expand Up @@ -145,7 +163,7 @@ def triples(triple, context = nil, &block) # :yields: triple, context
osp = @osp
else
ci = resource_to_int(context)
return [] unless ci
return [] if context.frozen? || !ci
spo = @cspo[ci]
pos = @cpos[ci]
osp = @cosp[ci]
Expand Down Expand Up @@ -354,6 +372,8 @@ def int_to_resource(i); @forward[i]; end
def triple_to_int(triple)
[@reverse[triple.subject.hash], @reverse[triple.predicate.hash], @reverse[triple.object.hash]]
end
def resource_to_int(resource); @reverse[resource.hash]; end
def resource_to_int(resource);
@reverse[resource.hash]
end
end
end

0 comments on commit fd0168d

Please sign in to comment.