Skip to content

Commit

Permalink
Preserve Open-Closed Principle with name mangling (#389)
Browse files Browse the repository at this point in the history
  • Loading branch information
brainix authored May 7, 2021
1 parent f2e36d5 commit cac37e8
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pottery/hyper.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ def __init__(self,
into this HyperLogLog.
'''
super().__init__(redis=redis, key=key)
self.update(iterable)
self.__update(iterable)

def add(self, value: RedisValues) -> None:
'Add an element to the HyperLogLog. O(1)'
self.update({value})
self.__update({value})

def update(self,
*objs: Union['HyperLogLog', Iterable[RedisValues]],
Expand All @@ -85,6 +85,11 @@ def update(self,
pipeline.pfmerge(self.key, *other_hll_keys)
pipeline.pfadd(self.key, *encoded_values)

# Preserve the Open-Closed Principle with name mangling.
# https://youtu.be/miGolgp9xq8?t=2086
# https://stackoverflow.com/a/38534939
__update = update

def union(self,
*objs: Iterable[RedisValues],
redis: Optional[Redis] = None,
Expand Down

0 comments on commit cac37e8

Please sign in to comment.