[xiph-commits] r3195 - oogg/trunk

shans at svn.annodex.net shans at svn.annodex.net
Thu Aug 16 03:20:19 PDT 2007


Author: shans
Date: 2007-08-16 03:20:18 -0700 (Thu, 16 Aug 2007)
New Revision: 3195

Modified:
   oogg/trunk/oogg_dump_packets.ml
   oogg/trunk/packet.ml
   oogg/trunk/streamSort.ml
   oogg/trunk/streamSort.mli
Log:
Fixed sorting (was waiting for end-of-stream, and suffering from order-n append on lists, so I added exception handling and Queues instead).
Added print debug function to sort input module



Modified: oogg/trunk/oogg_dump_packets.ml
===================================================================
--- oogg/trunk/oogg_dump_packets.ml	2007-08-16 07:38:00 UTC (rev 3194)
+++ oogg/trunk/oogg_dump_packets.ml	2007-08-16 10:20:18 UTC (rev 3195)
@@ -3,7 +3,4 @@
 let ps = Page.to_pageStream s;;
 let pps = Packet.to_packetStream ps;;
 let ppps = Packet.reconstruct_timing pps;;
-let all_streams = Packet.sort ppps;;
-Packet_util.print_packetStream 
-        (*ppps;;*) 
-        (snd (List.nth all_streams (int_of_string Sys.argv.(2))));;
+Packet_util.print_packetStream ppps;;

Modified: oogg/trunk/packet.ml
===================================================================
--- oogg/trunk/packet.ml	2007-08-16 07:38:00 UTC (rev 3194)
+++ oogg/trunk/packet.ml	2007-08-16 10:20:18 UTC (rev 3195)
@@ -114,8 +114,9 @@
     type s = packet
     let eq = (=)
     let get_key p = p.p_page.raw.serialno
-    let is_first p = p.p_page.raw.bos && p.p_pageno = 0
+    let is_first p = p.p_page.raw.bos
     let is_last p = p.p_page.raw.eos
+    let printKey s = print_oogg32 s
   end;;
 
 module PacketSort = StreamSort.StreamSort (PacketInput);;

Modified: oogg/trunk/streamSort.ml
===================================================================
--- oogg/trunk/streamSort.ml	2007-08-16 07:38:00 UTC (rev 3194)
+++ oogg/trunk/streamSort.ml	2007-08-16 10:20:18 UTC (rev 3195)
@@ -6,6 +6,7 @@
     val get_key : s -> k
     val is_first : s -> bool
     val is_last : s -> bool
+    val printKey : k -> unit
   end;;
 
 module StreamSort = 
@@ -20,7 +21,9 @@
           | Some page when I.is_first page  -> 
               (
                 Stream.junk i; 
-                (I.get_key page, ref (Some [page]))::(get_first_pages i)
+                let q = Queue.create () in
+                Queue.add page q;
+                (I.get_key page, ref (Some q))::(get_first_pages i)
               )
           | Some page                       -> [] in
       
@@ -30,15 +33,17 @@
           let cache = List.assoc k starts in
           match !cache with
             | None        -> None
-            | Some (h::t) ->
+            | Some q when not (Queue.is_empty q) ->
                 (
+                  let h = Queue.take q in
                   if I.is_last h 
                   then cache := None
-                  else cache := Some t;
+                  else cache := Some q;
                   Some h
                 )
-            | Some [] ->
-                ( let p = Stream.next i in
+            | Some _ ->
+                try (
+                  let p = Stream.next i in
                   let ik = I.get_key p in
                   if ik = k then (
                     if I.is_last p then cache := None;
@@ -47,10 +52,10 @@
                     let icache = List.assoc ik starts in
                     (match !icache with
                       | None   -> raise PagesAfterEOS
-                      | Some l -> icache := Some (l @ [p]));
+                      | Some q -> Queue.add p q);
                     get_next_page k
                   )
-                ) in
+                ) with Stream.Failure -> None in
 
         let generator k _ = get_next_page k in
         

Modified: oogg/trunk/streamSort.mli
===================================================================
--- oogg/trunk/streamSort.mli	2007-08-16 07:38:00 UTC (rev 3194)
+++ oogg/trunk/streamSort.mli	2007-08-16 10:20:18 UTC (rev 3195)
@@ -6,6 +6,7 @@
     val get_key : s -> k
     val is_first : s -> bool
     val is_last : s -> bool
+    val printKey : k -> unit
   end;;
 
 module StreamSort : 



More information about the commits mailing list