stdcompat__queue.ml1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85include Queue (* let take_opt q = try Some (take q) with Empty -> raise Empty let peek_opt q = try Some (peek q) with Empty -> raise Empty *) (* [@@@ocaml.warning "-37"] type 'a cell = | Nil | Cons of { content: 'a; mutable next: 'a cell } type 'a internal = { mutable length: int; mutable first: 'a cell; mutable last: 'a cell } let to_seq (q : 'a t) = let q : 'a internal = Obj.magic q in let rec aux c () = match c with | Nil -> Stdcompat__seq.Nil | Cons { content=x; next; } -> Stdcompat__seq.Cons (x, aux next) in aux q.first (* type 'a cell = { content: 'a; mutable next: 'a cell } type 'a internal = { mutable length: int; mutable tail: 'a cell } let to_seq (q : 'a t) = let q : 'a internal = Obj.magic q in if q.length = 0 then Stdcompat__seq.empty else begin let tail = q.tail in let rec aux cell () = let tail' = if cell == tail then Stdcompat__seq.empty else aux cell.next in Stdcompat__seq.Cons (cell.content, tail') in aux tail.next end *) (* let to_list q = fold (fun accu content -> content :: accu) [] q let to_seq q = Stdcompat__list.to_seq (List.rev (to_list q)) *) let add_seq q i = Stdcompat__seq.iter (fun x -> push x q) i let of_seq g = let q = create() in add_seq q g; q *) (* let drop q = ignore (take q) *)