home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / BIPL.ZIP / PROCS.ZIP / TBLUTIL.ICN < prev    next >
Encoding:
Text File  |  1992-09-28  |  2.1 KB  |  109 lines

  1. ############################################################################
  2. #
  3. #    File:     tblutil.icn
  4. #
  5. #    Subject:  Procedures for table manipulation
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     May 9, 1992
  10. #
  11. ###########################################################################
  12. #
  13. #  These procedures provide various operations on tables, most of which
  14. #  provide an approximation of set operations.  Since tables are, in general,
  15. #  many-to-one maps, the correspondences are only approximate and do not
  16. #  have the mathematical properties of the corresponding operations on
  17. #  sets.  For example, table "union" is not symmetric or transitive.
  18. #
  19. #  Where there is potential asymmetry, the procedures "favor" their
  20. #  first argument.
  21. #
  22. #  All the procedures that return tables return new tables and do not
  23. #  modify their arguments.
  24. #
  25. #  tblunion(T1, T2) approximates T1 ++ T2.
  26. #
  27. #  tblinter(T1, T2) approximages T1 ** T2.
  28. #
  29. #  tbldiff(T1, T2) approximates T1 -- T2.
  30. #
  31. #  tblfold(T) produces a two-tay table based on T.
  32. #
  33. #  tblinvrt(T) produces a table whose keys are T's values and whose
  34. #  values are T's keys.
  35. #
  36. #  tbldflt(T) produces the default value for T.
  37. #
  38. ############################################################################
  39. #
  40. #  See also:  twt.icn
  41. #
  42. ############################################################################
  43.  
  44. procedure tblunion(T1, T2)
  45.    local T3, x
  46.  
  47.    T3 := copy(T1)
  48.  
  49.    every x := key(T2) do
  50.       insert(T3, x, T2[x])
  51.  
  52.    return T3
  53.  
  54. end
  55.  
  56. procedure tblinter(T1, T2)
  57.    local T3, x
  58.  
  59.    T3 := table(tbldflt(T1))
  60.  
  61.    every x := key(T1) do
  62.       if member(T2, x) then insert(T3, x, T1[x])
  63.    
  64.    return T3
  65.  
  66. end
  67.  
  68. procedure tbldiff(T1, T2)
  69.    local T3, x
  70.  
  71.    T3 := copy(T1)
  72.  
  73.    every x := key(T2) do
  74.       delete(T3, x)
  75.  
  76.    return T3
  77.  
  78. end
  79.  
  80. procedure tblinvrt(T)
  81.    local T1, x
  82.  
  83.    T1 := table(tbldflt(T))
  84.  
  85.    every x := key(T) do
  86.       insert(T1, T[x], x)
  87.  
  88.    return T1
  89.  
  90. end
  91.  
  92. procedure tblfold(T)
  93.    local T1, x
  94.  
  95.    T1 := copy(T)
  96.  
  97.    every x := key(T) do
  98.       insert(T1, T[x], x)
  99.  
  100.    return T1
  101.  
  102. end
  103.  
  104. procedure tbldflt(T)
  105.  
  106.    return T[[]]
  107.  
  108. end
  109.