1 (* Copyright (C) 1999-2008 Henry Cejtin, Matthew Fluet, Suresh
2 * Jagannathan, and Stephen Weeks.
4 * MLton is released under a BSD-style license.
5 * See the file MLton-LICENSE for details.
8 functor PropertyList (H: HET_CONTAINER):> PROPERTY_LIST =
11 datatype t = T of H.t list ref
13 fun new (): t = T (ref [])
15 fun length (T r) = List.length (!r)
17 val equals = fn (T r, T r') => Ref.equals (r, r')
19 fun clear (T hs) = hs := []
21 val numPeeks: Int64.int ref = ref 0
22 val numLinks: Int64.int ref = ref 0
23 val maxLength: int ref = ref 0
28 [seq [str "property list numPeeks = ", str (Int64.toString (!numPeeks))],
29 (* seq [str "property list numLinks = ", str (Int64.toString (!numLinks))], *)
30 seq [str "property list maxLength = ", Int.layout (!maxLength)],
31 seq [str "property list average position = ",
33 val fromInt = fromIntInf o Int64.toLarge
34 in format (fromInt (!numLinks) / fromInt (!numPeeks),
39 fun 'a newProperty () =
41 val {make, pred, peek = peekH} = H.new ()
47 ((numLinks := Int64.fromInt n + !numLinks
48 handle Overflow => Error.bug "PropertyList: numLinks overflow")
53 [] => (update (); NONE)
56 r as SOME _ => (update (); r)
57 | NONE => loop (l, n + 1)
60 numPeeks := 1 + !numPeeks
61 handle Overflow => Error.bug "PropertyList: numPeeks overflow"
66 fun add (T hs, v: 'a): unit = hs := make v :: !hs
68 fun remove (T hs) = hs := List.remove (!hs, pred)
70 {add = add, peek = peek, remove = remove}