aboutsummaryrefslogtreecommitdiffstats
path: root/lib/evaluators
diff options
context:
space:
mode:
authorMarcos Magueta <maguetamarcos@gmail.com>2026-10-31 03:14:07 -0300
committerMarcos Magueta <maguetamarcos@gmail.com>2026-10-31 03:14:07 -0300
commita8cd08bfe473f01f245a4808e63809ed1cddc0e7 (patch)
treeff9f4d3875fadd157e982f3a98ea026dfaea3f8b /lib/evaluators
parent97dc56016bd0c7ddea4445c5ea5978220cc9e776 (diff)
downloadRNT-a8cd08bfe473f01f245a4808e63809ed1cddc0e7.tar.gz
RNT-a8cd08bfe473f01f245a4808e63809ed1cddc0e7.zip
one cursor loop for filtering and projecting
Diffstat (limited to 'lib/evaluators')
-rw-r--r--lib/evaluators/FOL.ml43
1 files changed, 17 insertions, 26 deletions
diff --git a/lib/evaluators/FOL.ml b/lib/evaluators/FOL.ml
index e28222b..a7685bd 100644
--- a/lib/evaluators/FOL.ml
+++ b/lib/evaluators/FOL.ml
@@ -187,32 +187,23 @@ let rec modes =
index )
let project description relation =
- let open Utilities.Result in
- let* cursor = Protocols.Enumerable.cursor relation in
- let produce ~yield =
- let* scan = Protocols.Cursor.require cursor in
- let rec distinct seen =
- let* next = Protocols.Cursor.next scan in
- match next with
- | None -> Ok ()
- | Some tuple ->
- let tuple =
- { tuple with
- attributes=
- BatMap.String.filter
- (fun name _ -> BatMap.String.mem name description)
- tuple.Concepts.Tuple.attributes }
- in
- let key = Concepts.Tuple.hash tuple |> Concepts.Hash.to_raw_string in
- if BatSet.String.mem key seen then distinct seen
- else begin
- yield tuple;
- distinct (BatSet.String.add key seen)
- end
- in
- distinct BatSet.String.empty
- in
- Ok (Kernel.Generator.cursor_of ~finally:(fun () -> Protocols.Handle.release cursor) produce)
+ let seen = ref BatSet.String.empty in
+ Protocols.Enumerable.cursor relation
+ |> Result.map
+ (Kernel.Generator.filter_map (fun tuple ->
+ let tuple =
+ { tuple with
+ attributes=
+ BatMap.String.filter
+ (fun name _ -> BatMap.String.mem name description)
+ tuple.Concepts.Tuple.attributes }
+ in
+ let key = Concepts.Tuple.hash tuple |> Concepts.Hash.to_raw_string in
+ if BatSet.String.mem key !seen then None
+ else begin
+ seen := BatSet.String.add key !seen;
+ Some tuple
+ end ) )
let agrees binding {Concepts.Tuple.attributes; _} =
BatMap.String.for_all