Stdlib/Ring: fix ring's semantics
This commit is contained in:
parent
f898062fd4
commit
14b1ba2adc
@ -60,7 +60,9 @@ let test_overflow _ =
|
||||
assert_equal_bool ~msg:__LOC__ true (P2p_acl.PeerRing.mem set (a "baz"));
|
||||
P2p_acl.PeerRing.add set (a "zor");
|
||||
assert_equal_bool ~msg:__LOC__ true (P2p_acl.PeerRing.mem set (a "zor"));
|
||||
assert_equal_bool ~msg:__LOC__ false (P2p_acl.PeerRing.mem set (a "baz"))
|
||||
assert_equal_bool ~msg:__LOC__ false (P2p_acl.PeerRing.mem set (a "foo"));
|
||||
assert_equal_bool ~msg:__LOC__ true (P2p_acl.PeerRing.mem set (a "bar"));
|
||||
assert_equal_bool ~msg:__LOC__ true (P2p_acl.PeerRing.mem set (a "baz"))
|
||||
|
||||
let () =
|
||||
Alcotest.run ~argv:[|""|] "tezos-p2p" [
|
||||
|
@ -33,7 +33,11 @@ module Ring = struct
|
||||
|
||||
type 'a t = 'a raw ref
|
||||
|
||||
let create size = ref (Empty size)
|
||||
let create size =
|
||||
if size <= 0 then
|
||||
invalid_arg "Ring.create: size must be positive"
|
||||
else
|
||||
ref (Empty size)
|
||||
|
||||
let add r v =
|
||||
match !r with
|
||||
@ -52,7 +56,7 @@ module Ring = struct
|
||||
| Empty _ -> None
|
||||
| Inited s ->
|
||||
if s.pos >= Array.length s.data - 1 then
|
||||
Some (s.data.(s.pos mod Array.length s.data))
|
||||
Some (s.data.((s.pos + 1) mod Array.length s.data))
|
||||
else
|
||||
None in
|
||||
add r v ; replaced
|
||||
|
Loading…
Reference in New Issue
Block a user