@@ -26,52 +26,52 @@ type 'a cell = {
26
26
content : 'a ;
27
27
mutable next : 'a cell_opt
28
28
}
29
- and 'a cell_opt = 'a cell Caml_undefined_extern .t
29
+ and 'a cell_opt = 'a cell option
30
30
and 'a t = {
31
31
mutable length : int ;
32
32
mutable first : 'a cell_opt ;
33
33
mutable last : 'a cell_opt
34
34
}
35
- [ @@ bs.deriving abstract ]
35
+
36
36
37
37
let 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 }
42
42
43
43
(* Added to tail *)
44
44
let push_back (q :'a t ) (v : 'a ) =
45
45
let cell =
46
- Caml_undefined_extern. return @@
47
- cell
48
- ~content: v ~next: Caml_undefined_extern. empty
46
+ Some
47
+ {content= v ; next= None }
49
48
in
50
- match q |. lastGet |. Caml_undefined_extern. toOption with
49
+ match q.last with
51
50
| 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
55
54
| 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
59
58
60
- let is_empty_queue q = q |. lengthGet = 0
59
+ let is_empty_queue q = q . length = 0
61
60
62
61
(* pop from front *)
62
+
63
63
let 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
67
67
| 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 ;
71
71
content
72
72
| Some next ->
73
- q |. lengthSet ((q |. lengthGet) - 1 ) ;
74
- q |. firstSet next_cell ;
73
+ q . length < - q . length - 1 ;
74
+ q . first < - next_cell ;
75
75
content
76
76
77
77
0 commit comments