Mercurial > code > home > repos > streamed-graph
comparison src/layout/rdf_value.ts @ 114:4b33a479dc2f
fix layout test to match new layout return types. clean up UriPairMap
author | drewp@bigasterisk.com |
---|---|
date | Sat, 19 Mar 2022 16:12:49 -0700 |
parents | cbcd82d21356 |
children |
comparison
equal
deleted
inserted
replaced
113:4822d5621463 | 114:4b33a479dc2f |
---|---|
59 uniques.sort((a, b) => { | 59 uniques.sort((a, b) => { |
60 return a.id.localeCompare(b.id); | 60 return a.id.localeCompare(b.id); |
61 }); | 61 }); |
62 return uniques; | 62 return uniques; |
63 } | 63 } |
64 | |
65 // A default dict of Term[] with (NamedNode,NamedNode) pairs as keys. | |
66 // | |
67 // Immutable.Map<Immutable.Record<Uri,Uri>, Immutable.Set<Term>>() didn't seem to work. | |
68 export class UriPairMap { | |
69 _d = new Map<string, Term[]>(); | |
70 | |
71 _key(k1: NamedNode, k2: NamedNode): string { | |
72 return k1.id + "|" + k2.id; | |
73 } | |
74 | |
75 add(k1: NamedNode, k2: NamedNode, v: Term) { | |
76 const key = this._key(k1, k2); | |
77 let cur = this._d.get(key); | |
78 if (cur === undefined) { | |
79 cur = []; | |
80 this._d.set(key, cur); | |
81 } | |
82 cur.push(v); | |
83 } | |
84 | |
85 get(k1: NamedNode, k2: NamedNode): Term[] { | |
86 const key = this._key(k1, k2); | |
87 const v = this._d.get(key); | |
88 if (v === undefined) { | |
89 return []; | |
90 } | |
91 return v; | |
92 } | |
93 } |