home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rox.zip / set.rox < prev    next >
Text File  |  1994-04-08  |  3KB  |  125 lines

  1. :*------------------------------------------------------------------
  2. :* REXX Object eXtensions : set class
  3. :*------------------------------------------------------------------
  4.  
  5. :class set
  6.  
  7. :include collect.rox
  8.  
  9. :inherits collection
  10.  
  11. :vars index max
  12.  
  13. :*------------------------------------------------------------------
  14. :* create a set
  15. :*------------------------------------------------------------------
  16. :method init
  17.    index  = ""
  18.    max    = 0
  19.  
  20.    return ""
  21.  
  22. :*------------------------------------------------------------------
  23. :* return number of items in the set
  24. :*------------------------------------------------------------------
  25. :method size
  26.    return words(index)
  27.  
  28. :*------------------------------------------------------------------
  29. :* add an item to the set
  30. :*------------------------------------------------------------------
  31. :method add
  32.    value = arg(1)
  33.  
  34.    pos = position(value)
  35.    if (0 <> pos) then
  36.       return self
  37.  
  38.    max = max + 1
  39.    item.max  = value
  40.    index     = index max
  41.  
  42.    rc = RoxAddVar(self,"item."max)
  43.  
  44.    return self
  45.  
  46.    /*------------------------------------------------------------------
  47.     * find position of the item in item array
  48.     *------------------------------------------------------------------*/
  49.    position:
  50.       value = arg(1)
  51.  
  52.       do i = 1 to words(index)
  53.          ind = word(index,i)
  54.          if (item.ind = value) then
  55.             return ind
  56.       end
  57.  
  58.       return 0
  59.  
  60. :*------------------------------------------------------------------
  61. :* delete an item from the set
  62. :*------------------------------------------------------------------
  63. :method delete
  64.    value = arg(1)
  65.  
  66.    pos = position(value)
  67.    if (0 = pos) then
  68.       return self
  69.  
  70.    drop item.pos
  71.  
  72.    p = wordpos(index,pos)
  73.    index = deleteword(index,p)
  74.  
  75.    return self
  76.  
  77.    /*------------------------------------------------------------------
  78.     * find position of the item in item array
  79.     *------------------------------------------------------------------*/
  80.    position:
  81.       value = arg(1)
  82.  
  83.       do i = 1 to words(index)
  84.          ind = word(index,i)
  85.          if (item.ind = value) then
  86.             return ind
  87.       end
  88.  
  89.       return 0
  90.  
  91. :*------------------------------------------------------------------
  92. :* return if item in set
  93. :*------------------------------------------------------------------
  94. :method includes
  95.    value = arg(1)
  96.  
  97.    if (0 = position(value)) then
  98.       return 0
  99.  
  100.    return 1
  101.  
  102.    /*------------------------------------------------------------------
  103.     * find position of the item in item array
  104.     *------------------------------------------------------------------*/
  105.    position:
  106.       value = arg(1)
  107.  
  108.       do i = 1 to words(index)
  109.          ind = word(index,i)
  110.          if (item.ind = value) then
  111.             return ind
  112.       end
  113.  
  114.       return 0
  115.  
  116. :*------------------------------------------------------------------
  117. :* return item at a particular position
  118. :*------------------------------------------------------------------
  119. :method atIndex
  120.    ind = arg(1)
  121.    ind = word(index,ind)
  122.  
  123.    return item.ind
  124.  
  125.