Skip to content

Commit

Permalink
Merge pull request #35 from JustroX/fix-exported-topk-update
Browse files Browse the repository at this point in the history
Fix import of inner count min for TopK import
  • Loading branch information
Callidon authored Jul 7, 2021
2 parents df4b41f + 6ac5bc6 commit 93fa979
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/sketch/topk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ export default class TopK extends BaseFilter {
@Field()
private _accuracy: number

@Field()
@Field<CountMinSketch>(
(sketch: CountMinSketch) => sketch.saveAsJSON(),
(json: any) => CountMinSketch.fromJSON(json)
)
private _sketch: CountMinSketch

@Field<MinHeap>((heap: MinHeap) => heap.content, (json: any) => {
Expand Down
21 changes: 21 additions & 0 deletions test/topk-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,5 +285,26 @@ describe('TopK', () => {
(() => TopK.fromJSON(json)).should.throw(Error)
})
})

it('should update an imported TopK', ()=>{
const exported = topk.saveAsJSON()
const newSketch = TopK.fromJSON(exported)

newSketch.add("alice")
topk.add("alice")

newSketch._k.should.equal(topk._k)
newSketch._errorRate.should.equal(topk._errorRate)
newSketch._accuracy.should.equal(topk._accuracy)
newSketch._seed.should.equal(topk._seed)
// inner count min sketch
newSketch._sketch._columns.should.equal(topk._sketch._columns)
newSketch._sketch._rows.should.equal(topk._sketch._rows)
newSketch._sketch._allSums.should.equal(topk._sketch._allSums)
newSketch._sketch._seed.should.equal(topk._sketch._seed)
newSketch._sketch._matrix.should.deep.equal(topk._sketch._matrix)
// inner MinHeap
newSketch._heap._content.should.deep.equal(topk._heap._content)
})
})
})

0 comments on commit 93fa979

Please sign in to comment.