wip
parent
40343490f2
commit
0dd99501e5
|
|
@ -14,9 +14,9 @@ def main():
|
||||||
|
|
||||||
def get_args():
|
def get_args():
|
||||||
ap = argparse.ArgumentParser()
|
ap = argparse.ArgumentParser()
|
||||||
ap.add_argument("-n", type=int, help="queue capacity", default=3)
|
ap.add_argument("-n", type=float, help="queue capacity", default=3)
|
||||||
ap.add_argument("-m", type=int, help="queue fill line", default=3)
|
ap.add_argument("-m", type=float, help="queue fill line", default=3)
|
||||||
ap.add_argument("-r", type=int, help="drain rate per second", default=2)
|
ap.add_argument("-r", type=float, help="drain rate per second", default=2)
|
||||||
ap.add_argument("-p", type=str, help="path to write out to", default="/tmp/cbappend.both.txt")
|
ap.add_argument("-p", type=str, help="path to write out to", default="/tmp/cbappend.both.txt")
|
||||||
return ap.parse_args()
|
return ap.parse_args()
|
||||||
|
|
||||||
|
|
@ -65,9 +65,10 @@ class Bucket():
|
||||||
self.CB = CB
|
self.CB = CB
|
||||||
self.__last_pop = 0
|
self.__last_pop = 0
|
||||||
self.__last_state = False
|
self.__last_state = False
|
||||||
|
self.__last_push = None
|
||||||
|
|
||||||
def push(self):
|
def push(self):
|
||||||
result = self.__push_c(1)
|
result = self.__push()
|
||||||
self.__cb()
|
self.__cb()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
@ -97,10 +98,15 @@ class Bucket():
|
||||||
def state(self):
|
def state(self):
|
||||||
return self.__last_state
|
return self.__last_state
|
||||||
|
|
||||||
def __push_c(self, c):
|
def __push(self):
|
||||||
self.__pop()
|
self.__pop()
|
||||||
|
c = 1
|
||||||
|
now = self.__now()
|
||||||
|
if self.__last_push:
|
||||||
|
c = min([now - self.__last_push, 1])
|
||||||
if self.q+c > self.N:
|
if self.q+c > self.N:
|
||||||
return False
|
return False
|
||||||
|
self.__last_push = now
|
||||||
self.q += c
|
self.q += c
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,6 @@ python3 ./testdata/rand_0_n_weighted_stream.py \
|
||||||
-w 3 \
|
-w 3 \
|
||||||
| peek \
|
| peek \
|
||||||
| python3 ./stream_to_state.py \
|
| python3 ./stream_to_state.py \
|
||||||
-n 7 \
|
-n 1 \
|
||||||
-m 6 \
|
-m .25 \
|
||||||
-r 6
|
-r .3
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue