Changeset - a07bfbe1e9de
[Not reviewed]
default
0 1 0
Drew Perttula - 7 years ago 2018-06-07 23:03:32
drewp@bigasterisk.com
make graph sortKey public
Ignore-this: f4c5a41044eb864d71a4ccb409de3c88
1 file changed with 11 insertions and 7 deletions:
0 comments (0 inline, 0 general)
light9/web/graph.coffee
Show inline comments
 
@@ -363,24 +363,26 @@ class window.SyncedGraph
 
        throw new Error(
 
          "list node #{current} has #{rests.length} rdf:rest edges")
 
      current = rests[0].object
 
    
 
    return out
 

	
 
  contains: (s, p, o) ->
 
    @_autoDeps.askedFor(s, p, o, null)
 
    return @graph.getQuads(s, p, o).length > 0
 

	
 
  nextNumberedResources: (base, howMany) ->
 
    # base is NamedNode or string
 
    # Note this is unsafe before we're synced with the graph. It'll
 
    # always return 'name0'.
 
    base = base.id if base.id
 
    results = []
 

	
 
    # @contains is really slow.
 
    @_nextNumber = new Map() unless @_nextNumber?
 
    start = @_nextNumber.get(base)
 
    if start == undefined
 
      start = 0
 
      
 
    for serial in [start..1000]
 
      uri = @Uri("#{base}#{serial}")
 
      if not @contains(uri, null, null)
 
@@ -391,30 +393,32 @@ class window.SyncedGraph
 
    throw new Error("can't make sequential uri with base #{base}")
 

	
 
  nextNumberedResource: (base) ->
 
    @nextNumberedResources(base, 1)[0]
 

	
 
  contextsWithPattern: (s, p, o) ->
 
    @_autoDeps.askedFor(s, p, o, null)
 
    ctxs = []
 
    for q in @graph.getQuads(s, p, o)
 
      ctxs.push(q.graph)
 
    return _.unique(ctxs)
 

	
 
  sortKey: (uri) ->
 
    parts = uri.value.split(/([0-9]+)/)
 
    expanded = parts.map (p) ->
 
      f = parseInt(p)
 
      return p if isNaN(f)
 
      return p.padStart(8, '0')
 
    return expanded.join('')
 

	
 
  sortedUris: (uris) ->
 
    _.sortBy uris, (u) ->
 
      parts = u.value.split(/([0-9]+)/)
 
      expanded = parts.map (p) ->
 
        f = parseInt(p)
 
        return p if isNaN(f)
 
        return p.padStart(8, '0')
 
      return expanded.join('')
 
    _.sortBy uris, @sortKey
 

	
 
  # temporary optimization since autodeps calls too often
 
  @patchContainsPreds: (patch, preds) ->
 
    patchContainsPreds(patch, preds)
 

	
 
  prettyLiteral: (x) ->
 
    if typeof(x) == 'number'
 
      @LiteralRoundedFloat(x)
 
    else
 
      @Literal(x)
0 comments (0 inline, 0 general)