Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 38 lines (33 sloc) 1.385 kB
2d5ff4a [enhance] libbase: add RAList
Raja authored
1 (** result of a comparison *)
2 type comparison = Lesser | Equal | Greater
3 (** invalid access of the ith element when only n elements (Invalid_subscript(i,n)) *)
4 exception Invalid_subscript of (int*int)
5 (** invalid operation on empty ra_list *)
6 exception Empty
7
8 type 'a ra_list
9
10 (** classic operations of list, all O(1) *)
11 module AsList :
12 sig
13 exception StopFold (*to implement fold until *)
14 val is_empty : 'a ra_list -> bool
15 val empty : 'a ra_list
16 val cons : 'a -> 'a ra_list -> 'a ra_list
17 val head : 'a ra_list -> 'a (* raise Empty *)
18 val tail : 'a ra_list -> 'a ra_list (* raise Empty *)
19 val fold : ('a->'b->'b) -> 'a ra_list -> 'b -> 'b (* catch StopFold to implement fold until *)
20 val rev_fold : ('a->'b->'b) -> 'a ra_list -> 'b -> 'b (* catch StopFold to implement fold until *)
21 end
22
23 (** classic operations of functional array, O(ln(N)) *)
24 module AsArray :
25 sig
26 val size : 'a ra_list -> int
27 val get : 'a ra_list -> int -> 'a (* raise Invalid_subscript *)
28 val update : 'a ra_list -> int -> 'a -> 'a ra_list (* raise Invalid_subscript *)
29 end
30
31 module AsMonotoniousList :
32 sig
33 (** return the lastest entry that is <= hypothetical asked entry,
34 via the comparison function which asked entry has already been passed to (facilitate comparison on projection) *)
35 val get_lesser : ('a -> comparison ) -> 'a ra_list -> 'a (* raise Not_found *)
36 (* val get *)
37 end
Something went wrong with that request. Please try again.