Initial implementation of Series in series.py
This commit is contained in:
parent
5894fb5d68
commit
b3eeeab4d7
1 changed files with 24 additions and 0 deletions
24
lib/xmet/series.py
Normal file
24
lib/xmet/series.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
from typing import Self
|
||||
|
||||
from xmet.util import cmp
|
||||
from xmet.list import nearest
|
||||
|
||||
class Series(dict):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
def intersect(self, series: Self):
|
||||
pairs = nearest(sorted(self.keys(), reverse=True),
|
||||
sorted(series.keys(), reverse=True))
|
||||
|
||||
sign_last = None
|
||||
|
||||
for pair in pairs:
|
||||
v1, v2 = self[pair[0]], series[pair[1]]
|
||||
|
||||
sign = cmp(v1, v2)
|
||||
|
||||
if sign == 0 or (sign_last is not None and sign_last != sign):
|
||||
return pair[0]
|
||||
|
||||
sign_last = sign
|
Loading…
Add table
Reference in a new issue