package pfff

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file oassoch.ml

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
33
34
35
36
37
38
open Common

open Oassoc

(* !!take care!!: this class does side effect, not a pure oassoc *)
class ['a,'b] oassoch xs = 
  let h = Common.hash_of_list xs in
  object(o)
    inherit ['a,'b] oassoc

    val data = h

    method empty = {< data = Hashtbl.create 101 >}
    method add (k,v) = (Hashtbl.replace data k v; o) (* not add cos add make iter sux *)

    (* redefine replkey to be more efficient than default. With hash, don't need
       to delkey before add, replace do both action directly.
     *)
    method replkey (k,v) = (Hashtbl.replace data k v; o)
    method iter f = Hashtbl.iter (Common2.curry f) data
    method view = raise Todo

    method del (k,v) = (Hashtbl.remove data k; o)
    method mem e = raise Todo
    method null = (try (Hashtbl.iter (fun k v -> raise Common2.ReturnExn) data; false) with Common2.ReturnExn -> true)

    method assoc k = 
      try 
        Hashtbl.find data k
      with Not_found -> (Common2.log3 ("pb assoc with k = " ^ (Dumper.dump k)); raise Not_found) 
        
    method delkey k = (Hashtbl.remove data k; o)

    method keys = 
      List.map fst (o#tolist)

end     

OCaml

Innovation. Community. Security.