From 505777b728ebe217472d3d906f2fae8bacfedc3f Mon Sep 17 00:00:00 2001 From: Daniel M Date: Thu, 25 Jan 2024 11:10:58 -0500 Subject: [PATCH] fix:calculation of elements_added on join (#119) * fix:calculation of elements_added on join --- probables/countminsketch/countminsketch.py | 2 +- tests/countminsketch_test.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/probables/countminsketch/countminsketch.py b/probables/countminsketch/countminsketch.py index 2bebe66..545348f 100644 --- a/probables/countminsketch/countminsketch.py +++ b/probables/countminsketch/countminsketch.py @@ -391,7 +391,7 @@ def join(self, second: "CountMinSketch") -> None: self._bins[i] = tmp_els # handle adding and removing elements added including handling overflow - self.__elements_added += self.elements_added + self.__elements_added += second.elements_added if self.elements_added > INT64_T_MAX: self.__elements_added = INT64_T_MAX diff --git a/tests/countminsketch_test.py b/tests/countminsketch_test.py index 323c69a..085484d 100755 --- a/tests/countminsketch_test.py +++ b/tests/countminsketch_test.py @@ -322,6 +322,7 @@ def test_cms_join(self): self.assertEqual(189 * 2, cms1.check("this is another test")) self.assertEqual(16 * 2, cms1.check("this is also a test")) self.assertEqual(5 * 2, cms1.check("this is something to test")) + self.assertEqual(cms1.elements_added, (255 + 189 + 16 + 5) * 2) def test_cms_join_overflow(self): """test count-min sketch overflow"""