@@ -26,52 +26,52 @@ type 'a cell = {
2626 content : 'a ;
2727 mutable next : 'a cell_opt
2828}
29- and 'a cell_opt = 'a cell Caml_undefined_extern .t
29+ and 'a cell_opt = 'a cell option
3030and 'a t = {
3131 mutable length : int ;
3232 mutable first : 'a cell_opt ;
3333 mutable last : 'a cell_opt
3434}
35- [ @@ bs.deriving abstract ]
35+
3636
3737let create_queue () =
38- t
39- ~ length: 0
40- ~ first: Caml_undefined_extern. empty
41- ~ last: Caml_undefined_extern. empty
38+ {
39+ length= 0 ;
40+ first = None ;
41+ last= None }
4242
4343(* Added to tail *)
4444let push_back (q :'a t ) (v : 'a ) =
4545 let cell =
46- Caml_undefined_extern. return @@
47- cell
48- ~content: v ~next: Caml_undefined_extern. empty
46+ Some
47+ {content= v ; next= None }
4948 in
50- match q |. lastGet |. Caml_undefined_extern. toOption with
49+ match q.last with
5150 | None ->
52- q |. lengthSet 1 ;
53- q |. firstSet cell;
54- q |. lastSet cell
51+ q . length < - 1 ;
52+ q . first < - cell;
53+ q . last < - cell
5554 | Some last ->
56- q |. lengthSet ((q |. lengthGet) + 1 ) ;
57- last |. nextSet cell;
58- q |. lastSet cell
55+ q . length < - q . length + 1 ;
56+ last . next < - cell;
57+ q . last < - cell
5958
60- let is_empty_queue q = q |. lengthGet = 0
59+ let is_empty_queue q = q . length = 0
6160
6261(* pop from front *)
62+
6363let unsafe_pop (q : 'a t ) =
64- let cell = (Obj. magic (q |. firstGet ) : 'a cell) in
65- let content, next_cell = cell |. (contentGet, nextGet) in
66- match Caml_undefined_extern. toOption next_cell with
64+ let cell = (Obj. magic (q . first ) : 'a cell) in
65+ let content, next_cell = cell.content , cell.next in
66+ match next_cell with
6767 | None ->
68- q |. lengthSet 0 ;
69- q |. firstSet Caml_undefined_extern. empty ;
70- q |. lastSet Caml_undefined_extern. empty ;
68+ q . length < - 0 ;
69+ q . first < - None ;
70+ q . last < - None ;
7171 content
7272 | Some next ->
73- q |. lengthSet ((q |. lengthGet) - 1 ) ;
74- q |. firstSet next_cell ;
73+ q . length < - q . length - 1 ;
74+ q . first < - next_cell ;
7575 content
7676
7777
0 commit comments