Commit 75fc1ebd authored by Pietro Abate's avatar Pietro Abate

[r2004-07-08 18:02:09 by cmiachon] adding avg and count. todo : sum, avg, min...

[r2004-07-08 18:02:09 by cmiachon] adding avg and count. todo : sum, avg, min and max, [Int+] instead of
[Int*]

Original author: cmiachon
Date: 2004-07-08 18:02:09+00:00
parent 861beeb3
......@@ -653,3 +653,24 @@ let query_sum = function
in Integer(Intervals.V.from_int(aux p (Intervals.V.get_int(i))))
|_ -> assert false
let query_avg = function
| Pair(Integer i,p) ->
let rec aux l i n = match l with
| Pair(Integer j,r) -> aux r (i+Intervals.V.get_int(j)) (n+1)
| Atom(_) -> i/(n+1)
| _ -> assert false
in Integer(Intervals.V.from_int(aux p (Intervals.V.get_int(i)) 0))
|_ -> assert false
let query_count = function
| Pair(Integer i,p) ->
let rec aux l n = match l with
| Pair(Integer _,r) -> aux r (n+1)
| Atom(_) -> n
| _ -> assert false
in Integer(Intervals.V.from_int(aux p 1))
| Atom a when a = Sequence.nil_atom -> Integer (Intervals.V.from_int 0)
|_ -> assert false
(* todo : sum, avg, min and max [Int+] instead of [Int*] *)
......@@ -120,4 +120,6 @@ val print_utf8: U.t -> unit
val query_min: t-> t
val query_max: t-> t
val query_sum: t-> t
val query_sum: t-> t
val query_avg: t-> t
val query_count: t-> t
......@@ -324,3 +324,10 @@ register_fun "max" Sequence.int int
register_fun "sum" Sequence.int int
(Value.query_sum );;
register_fun "avg" Sequence.int int
(Value.query_avg );;
register_fun "count" Sequence.int int
(Value.query_count );;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment