30011aa6dc42 — Chris Cannam 2 years ago
Rename the trie-map function "modify" to "alter". The term modify is used in the Basis Array for a map-like mass update function, and as this is now implemented in our PersistentArray as well, the term had become rather confusing.
M atrie-node-map-fn.sml +1 -1
@@ 105,7 105,7 @@ functor ATrieNodeMapFn (E : ATRIE_ELEMEN
                                    }
         end
 
-    fun modify (m, k, f) =
+    fun alter (m, k, f) =
         case f (find (m, k)) of
             NONE => remove (m, k)
           | SOME i => insert (m, k, i)

          
M bitmapped-vector.sml +3 -3
@@ 249,7 249,7 @@ functor BitMappedVectorFn (V : BIT_VECTO
                 :: acc)
             [] b
             
-    fun modify ((b, v) : 'a vector, i : int, f : 'a option -> 'a option) : 'a vector =
+    fun alter ((b, v) : 'a vector, i : int, f : 'a option -> 'a option) : 'a vector =
         let val pc = V.popcount (b, i)
         in
             if V.sub (b, i)

          
@@ 276,10 276,10 @@ functor BitMappedVectorFn (V : BIT_VECTO
         end
 
     fun update (vec, i, x) =
-        modify (vec, i, fn _ => SOME x)
+        alter (vec, i, fn _ => SOME x)
 
     fun remove (vec, i) =
-        modify (vec, i, fn _ => NONE)
+        alter (vec, i, fn _ => NONE)
 
     fun foldli (f : (int * 'a * 'b -> 'b))
                (acc : 'b) ((b, v) : 'a vector) : 'b =

          
M btrie-node-map-fn.sml +1 -1
@@ 25,7 25,7 @@ functor BTrieNodeMapFn (E : BTRIE_ELEMEN
     fun foldli f = V.foldli (fn (i, x, acc) => f (E.invOrd i, x, acc))
     fun foldr f = V.foldr (fn (x, acc) => f (x, acc))
     fun foldri f = V.foldri (fn (i, x, acc) => f (E.invOrd i, x, acc))
-    fun modify (v, k, f) = V.modify (v, E.ord k, f)
+    fun alter (v, k, f) = V.alter (v, E.ord k, f)
     fun remove (v, k) = V.remove (v, E.ord k)
     fun keyCompare (k1, k2) = Int.compare (E.ord k1, E.ord k2)
                                 

          
M mtrie-node-map-fn.sml +1 -1
@@ 24,7 24,7 @@ functor MTrieNodeMapFn (E : MTRIE_ELEMEN
 
     fun remove (m, k) = #1 (M.remove (m, k))
 
-    fun modify (m, k, f) =
+    fun alter (m, k, f) =
         case find (m, k) of
             NONE => (case f NONE of
                          NONE => m

          
M persistent-hash-map-fn.sml +1 -1
@@ 44,7 44,7 @@ functor PersistentHashMapFn (Key : HASH_
     fun insert (m, k, v) =
         let val h = Key.hashVal k
         in
-            T.modify (m, h, fn eopt => SOME (addToEntry (h, k, v) eopt))
+            T.alter (m, h, fn eopt => SOME (addToEntry (h, k, v) eopt))
         end
 
     fun remove (m, k) =

          
M trie-map-fn.sml +27 -27
@@ 15,7 15,7 @@ signature TRIE_NODE_MAP = sig
     val foldli : (key * 'a * 'b -> 'b) -> 'b -> 'a map -> 'b
     val foldr : ('a * 'b -> 'b) -> 'b -> 'a map -> 'b
     val foldri : (key * 'a * 'b -> 'b) -> 'b -> 'a map -> 'b
-    val modify : 'a map * key * ('a option -> 'a option) -> 'a map
+    val alter : 'a map * key * ('a option -> 'a option) -> 'a map
     val remove : 'a map * key -> 'a map
     val keyCompare : key * key -> order
 end

          
@@ 90,7 90,7 @@ functor TrieMapFn (A : TRIE_MAP_FN_ARG)
                 (print "Not canonical: branch with non-canonical sub-branch\n"; false)
             else true
 
-    fun modify' (n, xx, f : 'a option -> 'a option) =
+    fun alter' (n, xx, f : 'a option -> 'a option) =
         if K.isEmpty xx
         then
             case n of

          
@@ 104,7 104,7 @@ functor TrieMapFn (A : TRIE_MAP_FN_ARG)
                    | SOME new =>
                      (* switch to inserting the existing item back into
                         a branch built on the new one *)
-                     modify' (newBranch (SOME new), kk, fn _ => SOME unrelated))
+                     alter' (newBranch (SOME new), kk, fn _ => SOME unrelated))
               | BRANCH (iopt, m) => BRANCH (f iopt, m)
         else (* xx is nonempty, so we are not at our leaf yet *)
             case n of

          
@@ 112,7 112,7 @@ functor TrieMapFn (A : TRIE_MAP_FN_ARG)
                 (case f NONE of
                      NONE => LEAF unrelated
                    | SOME new =>
-                     modify' (newBranch (SOME unrelated), xx, fn _ => SOME new))
+                     alter' (newBranch (SOME unrelated), xx, fn _ => SOME new))
               | TWIG (kk, existing) =>
                 (if K.equal (kk, xx)
                  then case f (SOME existing) of

          
@@ 122,25 122,25 @@ functor TrieMapFn (A : TRIE_MAP_FN_ARG)
                           NONE => TWIG (kk, existing)
                         | SOME new => 
                           if K.head kk = K.head xx (* e.g. XDEF next to XABC *)
-                          then let val nsub = modify' (newBranch NONE,
-                                                       K.tail xx,
-                                                       fn _ => SOME new)
+                          then let val nsub = alter' (newBranch NONE,
+                                                      K.tail xx,
+                                                      fn _ => SOME new)
                                    (* reinsert existing into new: *)
-                                   val nsub = modify' (nsub,
-                                                       K.tail kk,
-                                                       fn _ => SOME existing)
+                                   val nsub = alter' (nsub,
+                                                      K.tail kk,
+                                                      fn _ => SOME existing)
                                in
                                    BRANCH (NONE,
-                                           M.modify (M.new (), K.head xx,
-                                                     fn _ => SOME nsub))
+                                           M.alter (M.new (), K.head xx,
+                                                    fn _ => SOME nsub))
                                end
                           else (* e.g. CDEF next to GHIJ, both known nonempty *)
-                              modify' (modify' (newBranch NONE, kk,
-                                                fn _ => SOME existing),
-                                       xx, fn _ => SOME new))
+                              alter' (alter' (newBranch NONE, kk,
+                                              fn _ => SOME existing),
+                                      xx, fn _ => SOME new))
               | BRANCH (iopt, m) =>
                 BRANCH (iopt,
-                        M.modify
+                        M.alter
                             (m, K.head xx,
                              fn NONE =>
                                 (case f NONE of

          
@@ 153,18 153,18 @@ functor TrieMapFn (A : TRIE_MAP_FN_ARG)
                                                else TWIG (xs, new)
                                            end))
                              | SOME nsub =>
-                               let val nsub' = modify' (nsub, K.tail xx, f)
+                               let val nsub' = alter' (nsub, K.tail xx, f)
                                in
                                    if isEmptyBranch nsub'
                                    then NONE
                                    else SOME nsub'
                                end))
                                
-    fun modify (n, xx, f) =
-        let val n' = modify' (case n of
-                                  EMPTY => newBranch NONE
-                                | POPULATED n => n,
-                              xx, f)
+    fun alter (n, xx, f) =
+        let val n' = alter' (case n of
+                                 EMPTY => newBranch NONE
+                               | POPULATED n => n,
+                             xx, f)
         in
             if isEmptyBranch n'
             then EMPTY

          
@@ 178,10 178,10 @@ functor TrieMapFn (A : TRIE_MAP_FN_ARG)
         end
 
     fun insert (nopt, xx, v) =
-        modify (nopt, xx, fn _ => SOME v)
+        alter (nopt, xx, fn _ => SOME v)
                         
     fun remove (nopt, xx) =
-        modify (nopt, xx, fn _ => NONE)
+        alter (nopt, xx, fn _ => NONE)
 
     fun isPrefixOf ([], yy) = true
       | isPrefixOf (xx, []) = false

          
@@ 512,8 512,8 @@ functor TrieMapFn (A : TRIE_MAP_FN_ARG)
                     case extractPrefixNode (nsub, K.tail xx) of
                         EMPTY => EMPTY
                       | POPULATED nsub' => 
-                        POPULATED (BRANCH (NONE, M.modify (M.new (), K.head xx,
-                                                           fn _ => SOME nsub')))
+                        POPULATED (BRANCH (NONE, M.alter (M.new (), K.head xx,
+                                                          fn _ => SOME nsub')))
 
     fun extractPrefix (trie, e) =
         case trie of

          
@@ 750,7 750,7 @@ functor TrieMapFn (A : TRIE_MAP_FN_ARG)
                                                subConstraint (x, rc)) of
                                          EMPTY => acc
                                        | POPULATED nsub' =>
-                                         M.modify (acc, x, fn _ => SOME nsub'))
+                                         M.alter (acc, x, fn _ => SOME nsub'))
                             (M.new ())
                             m
                 in

          
M trie-map-keyadapter-fn.sml +1 -1
@@ 31,7 31,7 @@ functor TrieMapKeyAdapterFn (A : TRIE_MA
     val isEmpty = T.isEmpty
 
     fun insert (t, k, x) = T.insert (t, enkey k, x)
-    fun modify (t, k, f) = T.modify (t, enkey k, f)
+    fun alter (t, k, f) = T.alter (t, enkey k, f)
     fun remove (t, k) = T.remove (t, enkey k)
     fun contains (t, k) = T.contains (t, enkey k)
     fun find (t, k) = T.find (t, enkey k)

          
M trie-map.sig +6 -4
@@ 13,11 13,13 @@ signature TRIE_MAP = sig
     (** Test whether a trie is empty *)
     val isEmpty : 'a trie -> bool
 
-    (** Modify a key-value pair in the trie, returning a new trie. The
+    (** Alter a key-value pair in the trie, returning a new trie. The
         function argument should map from the previous value
-        associated with the key (or NONE if it was absent before) to
-        the new value (or NONE if it is to be removed) *)
-    val modify : 'a trie * key * ('a option -> 'a option) -> 'a trie
+        associated with the key, or NONE if it was absent before, to
+        the new value, or NONE if it is to be removed. (This is called
+        alter rather than modify to avoid confusion with the array
+        modify functions, which do something rather different) *)
+    val alter : 'a trie * key * ('a option -> 'a option) -> 'a trie
 
     (** Insert a key-value pair, returning a new trie. If the key is
         already present, its value will be updated in the new trie *)

          
M word32-trie-map.sml +1 -1
@@ 14,7 14,7 @@ structure Word32NodeMap
     open V
              
     fun new () = V.new 32
-    fun update (v, k, f) = V.modify (v, k, fn x => SOME (f x))
+    fun update (v, k, f) = V.alter (v, k, fn x => SOME (f x))
     val keyCompare = Int.compare
                        
 end