Commits

bergsoe  committed 47f7a13

[nearest] utility.

  • Participants
  • Parent commits fc45798

Comments (0)

Files changed (1)

File src/PaplIndex.ml

     val shortest :
       t -> value_t PaplMetric.norm_t -> value_t option
 
+    val nearest :
+      t ->
+      (value_t -> 'a) ->
+      'a PaplMetric.option_t ->
+      'a PaplEdgeConstraint.t ->
+      'a ->
+      value_t option
+
     val choose_random : t -> value_t option
 
     val create : unit -> t
+
+    val enum : t -> value_t BatEnum.t
   end
 
   module type S_MARK = sig
 
     let create () = A.create ()
 
+    let enum s = A.enum s
+
     let add s x = A.add s x
 
     let option_shortest buffer norm_option =
           Some !min_item
       end
 
+    let nearest buffer get dist constr a =
+      let norm b = dist (get b) a in
+        match option_shortest buffer norm with
+          | None -> None
+          | Some b as result ->
+              if PaplConstraint.accept constr (get b, a)
+              then result
+              else None
+
     let int_fun = PaplRandom.int ~rng:M.rng
 
     let choose_random buffer =