File: algMap.ml

package info (click to toggle)
pplacer 1.1~alpha19-8
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 17,324 kB
  • sloc: ml: 20,927; ansic: 9,002; python: 1,641; makefile: 171; sh: 77; xml: 50
file content (32 lines) | stat: -rw-r--r-- 761 bytes parent folder | download | duplicates (2)
1
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
(* A map equipped with algebraic operations.
 *
 * not super-high performance because of map and boxing.
 *
 *)

module AlgMap (N: Number.NUMBER) (M: MapsSets.M) =
  struct
    include M

    let soft_find k m =
      try find k m with
      | Not_found -> N.zero

      (* sets k to (soft value of k) op v *)
    let soft_op_add op k v m =
      add k (op (soft_find k m) v) m

    let add_by = soft_op_add (N.add)
    let sub_by = soft_op_add (N.sub)
    let mul_by = soft_op_add (N.mul)
    let div_by = soft_op_add (N.div)
    let max_by = soft_op_add (N.max)
    let pow_by = soft_op_add (N.pow)
  end

module AlgMapB = AlgMap (Number.B)
module AlgMapZ = AlgMap (Number.Z)
module AlgMapR = AlgMap (Number.R)


module IntAlgMapR = AlgMapR (MapsSets.IntMap)