Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Diff of /smlnj-lib/trunk/Util/int-list-map.sml
ViewVC logotype

Diff of /smlnj-lib/trunk/Util/int-list-map.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 289, Sat May 22 21:01:25 1999 UTC revision 411, Fri Sep 3 00:25:03 1999 UTC
# Line 30  Line 30 
30      fun firsti [] = NONE      fun firsti [] = NONE
31        | firsti ((key, value)::_) = SOME(key, value)        | firsti ((key, value)::_) = SOME(key, value)
32    
33        fun singleton (key, item) = [(key, item)]
34    
35      fun insert (l, key, item) = let      fun insert (l, key, item) = let
36            fun f [] = [(key, item)]            fun f [] = [(key, item)]
37              | f ((elem as (key', _))::r) = (case Key.compare(key, key')              | f ((elem as (key', _))::r) = (case Key.compare(key, key')
# Line 42  Line 44 
44            end            end
45      fun insert' ((k, x), m) = insert(m, k, x)      fun insert' ((k, x), m) = insert(m, k, x)
46    
47      (* return true if the key is in the map's domain *)
48        fun inDomain (l, key) = let
49              fun f [] = false
50                | f ((key', x) :: r) = (key' <= key) andalso ((key' = key) orelse f r)
51              in
52                f l
53              end
54    
55    (* Look for an item, return NONE if the item doesn't exist *)    (* Look for an item, return NONE if the item doesn't exist *)
56      fun find (l, key) = let      fun find (l, key) = let
57            fun f [] = NONE            fun f [] = NONE
58              | f ((key', x) :: r) = (case Key.compare(key, key')              | f ((key', x) :: r) =
59                     of LESS => NONE                  if (key < key') then NONE
60                      | EQUAL => SOME x                  else if (key = key') then SOME x
61                      | GREATER => f r                  else f r
                   (* end case *))  
62            in            in
63              f l              f l
64            end            end
# Line 75  Line 84 
84      fun listItems (l : 'a map) = List.map #2 l      fun listItems (l : 'a map) = List.map #2 l
85      fun listItemsi l = l      fun listItemsi l = l
86    
87        fun listKeys (l : 'a map) = List.map #1 l
88    
89      fun collate cmpRng = let      fun collate cmpRng = let
90            fun cmp ([], []) = EQUAL            fun cmp ([], []) = EQUAL
91              | cmp ([], _) = LESS              | cmp ([], _) = LESS

Legend:
Removed from v.289  
changed lines
  Added in v.411

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0