home *** CD-ROM | disk | FTP | other *** search
- ############################################################################
- #
- # File: tblutil.icn
- #
- # Subject: Procedures for table manipulation
- #
- # Author: Ralph E. Griswold
- #
- # Date: May 9, 1992
- #
- ###########################################################################
- #
- # These procedures provide various operations on tables, most of which
- # provide an approximation of set operations. Since tables are, in general,
- # many-to-one maps, the correspondences are only approximate and do not
- # have the mathematical properties of the corresponding operations on
- # sets. For example, table "union" is not symmetric or transitive.
- #
- # Where there is potential asymmetry, the procedures "favor" their
- # first argument.
- #
- # All the procedures that return tables return new tables and do not
- # modify their arguments.
- #
- # tblunion(T1, T2) approximates T1 ++ T2.
- #
- # tblinter(T1, T2) approximages T1 ** T2.
- #
- # tbldiff(T1, T2) approximates T1 -- T2.
- #
- # tblfold(T) produces a two-tay table based on T.
- #
- # tblinvrt(T) produces a table whose keys are T's values and whose
- # values are T's keys.
- #
- # tbldflt(T) produces the default value for T.
- #
- ############################################################################
- #
- # See also: twt.icn
- #
- ############################################################################
-
- procedure tblunion(T1, T2)
- local T3, x
-
- T3 := copy(T1)
-
- every x := key(T2) do
- insert(T3, x, T2[x])
-
- return T3
-
- end
-
- procedure tblinter(T1, T2)
- local T3, x
-
- T3 := table(tbldflt(T1))
-
- every x := key(T1) do
- if member(T2, x) then insert(T3, x, T1[x])
-
- return T3
-
- end
-
- procedure tbldiff(T1, T2)
- local T3, x
-
- T3 := copy(T1)
-
- every x := key(T2) do
- delete(T3, x)
-
- return T3
-
- end
-
- procedure tblinvrt(T)
- local T1, x
-
- T1 := table(tbldflt(T))
-
- every x := key(T) do
- insert(T1, T[x], x)
-
- return T1
-
- end
-
- procedure tblfold(T)
- local T1, x
-
- T1 := copy(T)
-
- every x := key(T) do
- insert(T1, T[x], x)
-
- return T1
-
- end
-
- procedure tbldflt(T)
-
- return T[[]]
-
- end
-