-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle sharing of Index instances explicitly
- Loading branch information
Showing
15 changed files
with
220 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
(* The MIT License | ||
Copyright (c) 2019 Craig Ferguson <[email protected]> | ||
Thomas Gazagnaire <[email protected]> | ||
Ioana Cristescu <[email protected]> | ||
Clément Pascutto <[email protected]> | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. *) | ||
|
||
module type S = sig | ||
type ('k, 'v) t | ||
(** A cache of values of type ['v], indexed by keys of type ['k]. *) | ||
|
||
val create : unit -> (_, _) t | ||
|
||
val add : ('k, 'v) t -> 'k -> 'v -> unit | ||
|
||
val find : ('k, 'v) t -> 'k -> 'v option | ||
|
||
val remove : ('k, _) t -> 'k -> unit | ||
end | ||
|
||
(** Cache implementation that always misses. *) | ||
module Noop : S = struct | ||
type (_, _) t = unit | ||
|
||
let create () = () | ||
|
||
let add () _ _ = () | ||
|
||
let find () _ = None | ||
|
||
let remove () _ = () | ||
end | ||
|
||
(** Cache implementation that always finds previously-added values, and grows | ||
indefinitely. *) | ||
module Unbounded : S = struct | ||
include Hashtbl | ||
|
||
let create () = create 0 | ||
|
||
let find = find_opt | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
let check_none msg = Alcotest.(check (option reject)) msg None | ||
|
||
let check_some msg x = Alcotest.(check (option int)) msg (Some x) | ||
|
||
let test_noop () = | ||
let open Index.Cache.Noop in | ||
(* Test that added entries are never found. *) | ||
let c = create () in | ||
find c "not-added" |> check_none "Cannot find non-existent value"; | ||
add c "added" 1; | ||
find c "added" |> check_none "Cannot find added value"; | ||
remove c "added"; | ||
find c "added" |> check_none "Can't find added value after remove"; | ||
() | ||
|
||
let test_unbounded () = | ||
let open Index.Cache.Unbounded in | ||
(* Test that added entries are always found. *) | ||
let c = create () in | ||
find c "not-added" |> check_none "Cannot find non-existent value"; | ||
add c "added" 1; | ||
find c "added" |> check_some "Can find added value" 1; | ||
remove c "added"; | ||
find c "added" |> check_none "Can't find added value after remove"; | ||
() | ||
|
||
let tests = | ||
[ | ||
Alcotest.test_case "noop" `Quick test_noop; | ||
Alcotest.test_case "unbounded" `Quick test_unbounded; | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
(test | ||
(name search) | ||
(name main) | ||
(package index) | ||
(libraries index alcotest)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
let () = | ||
Alcotest.run "index" [ ("cache", Cache.tests); ("search", Search.tests) ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.