Commits

Yaron Minsky committed a66813e

added # strands

  • Participants
  • Parent commits e8d09ad

Comments (0)

Files changed (4)

File ocaml/iet.ml

 
 type t = { branch_by_strand : Branch.t Strand.Map.t Side_pair.t
          ; attachments : (attachment * attachment) Branch.Map.t
+         ; num_strands : int
          }
 with sexp
 
 let lookup_attachments t branch =
   Map.find_exn t.attachments branch
 
+let num_strands t = t.num_strands
+
 type annotated_branch =
   { start: Strand.t
   ; branch: Branch.t
                  <:sexp_of<Branch.t>>
       )
   in
-  { branch_by_strand; attachments }
+  let num_strands = Map.length branch_by_strand.top in
+  assert (num_strands = Map.length branch_by_strand.bot);
+  { branch_by_strand; attachments; num_strands }
     
 
 let create_simple branches ~widths =

File ocaml/iet.mli

 
 type t with sexp
 
+(** {2 Creation functions} *)
+
 val create
   :  Branch.t list Side_pair.t
   -> widths : int Branch.Map.t
   -> widths:int list
   -> t
 
+(** {2 Accessors} *)
+
+val num_strands : t -> int
+
 val lookup_branch
   :  t
   -> Strand.t

File ocaml/iet_utils.ml

 
 
 let in_range (low,high) x =
-  x >= low && x <= high
+  Strand.(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 *)
     else loop next (current :: accum)
   in
   loop start []
+
+let cycle_is_complete iet cycle =
+  List.length cycle = 2 * Iet.num_strands iet

File ocaml/iet_utils.mli

 
 val find_next  : Iet.t -> Strand.t * Side.t -> Strand.t * Side.t
 val find_cycle : Iet.t -> Strand.t * Side.t -> (Strand.t * Side.t) list
+val cycle_is_complete : Iet.t -> (Strand.t * Side.t) list -> bool