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

Implement Ring Map #11

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
42 changes: 42 additions & 0 deletions lib/conntest.ml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,27 @@ module Make
done;
!acc

let map_rev_shortcircuit f r =
let i = ref 0 in
let len = length r in
let ring_copy = Array.copy r.ring in
while !i < len do
let idx_opt = wrap_reverse_i r !i in
match idx_opt with
| None -> i := len
| Some idx ->
let value_opt = get_previous r !i in
match value_opt with
| None -> ring_copy.(idx) <- None; i := succ !i
| Some x ->
match f x with
| None -> i := len
| Some y ->
ring_copy.(idx) <- Some y; i := succ !i
done;
{ r with ring = ring_copy }


end

module Udp_flow = struct
Expand Down Expand Up @@ -348,6 +369,27 @@ module Make
*)
Log.debug (fun m -> m "feed_source: packet_index_diff < 0");
let did_set = ref false in
let map_rev_shortcircuit f r =
let i = ref 0 in
let len = Ring.length r in
let ring_copy = Array.copy r.Ring.ring in
while !i < len do
let idx_opt = Ring.wrap_reverse_i r !i in
match idx_opt with
| None -> i := len
| Some idx ->
let value_opt = Ring.get_previous r !i in
match value_opt with
| None -> ring_copy.(idx) <- None; i := succ !i
| Some x ->
match f x with
| None -> i := len
| Some y ->
ring_copy.(idx) <- Some y; i := succ !i
done;
{ r with Ring.ring = ring_copy }

in
(*> goto perf; could use something like 'find_map_rev'
* which would try the latest packets first -
* which should be more often hit
Expand Down