Commits

Yaron Minsky  committed e8d09ad

cleaned up attachment API a bit

  • Participants
  • Parent commits 9f382d3

Comments (0)

Files changed (4)

File ocaml/iet.ml

 open Core.Std
 open Common
 
-type branch_info =
-  { strands: Strand.t Interval.t
-  ; width: int
-  ; side: Side.t
-  } 
+type attachment =
+  { strand_range : Strand.t * Strand.t
+  ; side    : Side.t
+  }
 with sexp
 
 type t = { branch_by_strand : Branch.t Strand.Map.t Side_pair.t
-         ; branch_info : (branch_info * branch_info) Branch.Map.t
+         ; attachments : (attachment * attachment) Branch.Map.t
          }
 with sexp
 
 let lookup_branch t strand side =
   Map.find_exn (Side_pair.get t.branch_by_strand side) strand
 
-let lookup_branch_info t branch =
-  Map.find_exn t.branch_info branch
+let lookup_attachments t branch =
+  Map.find_exn t.attachments branch
 
 type annotated_branch =
   { start: Strand.t
                     Map.add map ~key:strand ~data:branch
                   )))
   in
-  let branch_info =
+  let attachments =
     annotated_branches
     |> List.map ~f:(fun ({branch;_} as annot) ->
         (branch,annot))
     |> Map.mapi ~f:(fun ~key:branch ~data:annots ->
         match annots with
         | [a1;a2] ->
-          let info ({start;branch=_;width;side} : annotated_branch) : branch_info =
-            { strands = Interval.create start Strand.(start +: Int.(width - 1))
-            ; width
-            ; side }
+          let info ({start;branch=_;width;side} : annotated_branch) : attachment =
+            { strand_range = (start,Strand.(start +: Int.(width - 1)))
+            ; side
+            }
           in
           (info a1, info a2)
         | _ -> failwiths "Branch should appear exactly twice" branch
                  <:sexp_of<Branch.t>>
       )
   in
-  { branch_by_strand; branch_info }
+  { branch_by_strand; attachments }
     
 
 let create_simple branches ~widths =
         Map.add map ~key:branch ~data:width)
   in
   create branches ~widths
+

File ocaml/iet.mli

   -> t
 
 val create_simple
-  : int list Side_pair.t
+  :  int list Side_pair.t
   -> widths:int list
   -> t
 
   -> Side.t
   -> Branch.t
 
-type branch_info =
-  { strands: Strand.t Interval.t
-  ; width: int
-  ; side: Side.t
+type attachment =
+  { strand_range : Strand.t * Strand.t
+  ; side    : Side.t
   }
 
-val lookup_branch_info
+val lookup_attachments
   :  t
   -> Branch.t
-  -> branch_info * branch_info
+  -> attachment * attachment

File ocaml/iet_utils.ml

 open Common
 
 
+let in_range (low,high) x =
+  x >= low && x <= high
+
 (* Given a strand and a side in an IET, find the strand/side pair
    that it is connected to by the branch in question *)
 let find_next iet (strand, side) =
-  let (binfo1,binfo2) =
+  let (attach1,attach2) =
     Iet.lookup_branch iet strand side
-    |> Iet.lookup_branch_info iet
+    |> Iet.lookup_attachments iet
   in
   (* Figure out the branch associated with this strand/side pair,
      and the branch it's connected to *)
-  let my_binfo,other_binfo =
-    if Interval.contains binfo1.strands strand
-    then (binfo1,binfo2)
+  let (mine,other) =
+    if in_range attach2.strand_range strand
+    then (attach1,attach2)
     else (
-      assert (Interval.contains binfo2.strands strand);
-      (binfo2,binfo1)
+      assert (in_range attach2.strand_range strand);
+      (attach2,attach1)
     )
   in
   (* We want an orientable surface, so we flip the strand order when
      reconnecting to the same side *)
   let should_flip =
-    my_binfo.side = other_binfo.side
+    mine.side = other.side
   in
   let other_strand =
-    let branch_start = Interval.lbound_exn my_binfo.strands in
+    let branch_start = fst mine.strand_range in
     let pos_in_branch = Strand.(strand - branch_start) in
     if not should_flip then
-      let branch_start = Interval.lbound_exn other_binfo.strands in
-      Strand.(branch_start +: pos_in_branch)
+      let other_branch_start = fst other.strand_range in
+      Strand.(other_branch_start +: pos_in_branch)
     else
-      let branch_end = Interval.ubound_exn other_binfo.strands in
-      Strand.(branch_end   -: pos_in_branch)
+      let other_branch_end = snd other.strand_range in
+      Strand.(other_branch_end   -: pos_in_branch)
   in
-  (other_strand,other_binfo.side)
+  (other_strand,other.side)
 
 let find_cycle iet start =
   let rec loop current accum =

File ocaml/side_pair.mli

 
 type 'a t = { top: 'a; bot: 'a } with sexp
 
-val get   : 'a t -> Side.t -> 'a
-val set   : 'a t -> Side.t -> 'a -> 'a t
-val of_fn : (Side.t -> 'a) -> 'a t
-val map   : 'a t -> f:('a -> 'b) -> 'b t
+val get    : 'a t -> Side.t -> 'a
+val set    : 'a t -> Side.t -> 'a -> 'a t
+val of_fn  : (Side.t -> 'a) -> 'a t
+val map    : 'a t -> f:('a -> 'b) -> 'b t
 val change : 'a t -> Side.t -> f:('a -> 'a) -> 'a t