Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve Open-Closed Principle with name mangling #389

Merged
merged 1 commit into from
May 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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