home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Moscow ML 1.42 / lib / Intset.sig < prev    next >
Encoding:
Text File  |  1997-08-18  |  2.5 KB  |  80 lines  |  [TEXT/Moml]

  1. (* Intset -- applicative sets of integers.
  2.  *
  3.  * Modified for Moscow ML from SML/NJ library version 0.2, which is
  4.  * COPYRIGHT (c) 1993 by AT&T Bell Laboratories.  
  5.  * See file mosml/copyrght/copyrght.att for details.
  6.  * Original implementation due to Stephen Adams, Southampton, UK.
  7.  *)
  8.  
  9. type intset
  10.  
  11. exception NotFound
  12.  
  13. val empty        : intset
  14. val singleton    : int -> intset
  15. val add          : intset * int -> intset
  16. val addList      : intset * int list -> intset
  17. val isEmpty      : intset -> bool
  18. val equal        : intset * intset -> bool
  19. val isSubset     : intset * intset -> bool
  20. val member       : intset * int -> bool
  21. val delete       : intset * int -> intset
  22. val numItems     : intset ->  int
  23. val union        : intset * intset -> intset
  24. val intersection : intset * intset -> intset
  25. val difference   : intset * intset -> intset
  26. val listItems    : intset -> int list
  27. val app          : (int -> unit) -> intset -> unit
  28. val revapp       : (int -> unit) -> intset -> unit
  29. val foldr        : (int * 'b -> 'b) -> 'b -> intset -> 'b
  30. val foldl        : (int * 'b -> 'b) -> 'b -> intset -> 'b
  31. val find         : (int -> bool) -> intset -> int option
  32.  
  33. (* This unit implements sets of integers.  
  34.  
  35.    [empty] is the empty set of integers.
  36.  
  37.    [singleton i] is the singleton set containing i.
  38.  
  39.    [add(s, i)] adds item i to set s.  
  40.  
  41.    [addList(s, xs)] adds all items from the list xs to the set s.
  42.  
  43.    [isEmpty s] returns true if and only if the set is empty.
  44.  
  45.    [equal(s1, s2)] returns true if and only if the two sets have the
  46.    same elements.
  47.  
  48.    [isSubset(s1, s2)] returns true if and only if s1 is a subset of s2.
  49.  
  50.    [member(s, i)] returns true if and only if i is in s.
  51.  
  52.    [delete(s, i)] removes item i from s.  Raises NotFound if i is not in s.
  53.    
  54.    [numItems s] returns the number of items in set s.
  55.  
  56.    [union(s1, s2)] returns the union of s1 and s2.  
  57.  
  58.    [intersection(s1, s2)] returns the intersectionof s1 and s2.
  59.  
  60.    [difference(s1, s2)] returns the difference between s1 and s2 (that
  61.    is, the set of elements in s1 but not in s2).
  62.  
  63.    [listItems s] returns a list of the items in set s.
  64.  
  65.    [app f s] applies function f to the elements of s, in increasing
  66.    order.
  67.  
  68.    [revapp f s] applies function f to the elements of s, in decreasing
  69.    order. 
  70.  
  71.    [foldl f e s] applies the folding function f to the entries of the
  72.    set in increasing order.
  73.  
  74.    [foldr f e s] applies the folding function f to the entries of the
  75.    set in decreasing order. 
  76.  
  77.    [find p s] returns SOME i, where i is an item in s which satisfies
  78.    p, if one exists; otherwise returns NONE.
  79. *)
  80.