◐ Shell
reader mode source ↗
Skip to content
This repository was archived by the owner on Dec 2, 2021. It is now read-only.
Open
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
10 changes: 8 additions & 2 deletions 10-seq-hacking/vector_v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ class Vector:

def __init__(self, components):
self._components = array(self.typecode, components)

def __iter__(self):
return iter(self._components)
Expand All @@ -177,12 +178,17 @@ def __bytes__(self):
bytes(self._components))

def __eq__(self, other):
return (len(self) == len(other) and
all(a == b for a, b in zip(self, other)))

def __hash__(self):
hashes = (hash(x) for x in self)
return functools.reduce(operator.xor, hashes, 0)

def __abs__(self):
return math.sqrt(sum(x * x for x in self))
Expand Down
Toggle all file notes Toggle all file annotations