home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 18 REXX
/
18-REXX.zip
/
rox.zip
/
set.rox
< prev
next >
Wrap
Text File
|
1994-04-08
|
3KB
|
125 lines
:*------------------------------------------------------------------
:* REXX Object eXtensions : set class
:*------------------------------------------------------------------
:class set
:include collect.rox
:inherits collection
:vars index max
:*------------------------------------------------------------------
:* create a set
:*------------------------------------------------------------------
:method init
index = ""
max = 0
return ""
:*------------------------------------------------------------------
:* return number of items in the set
:*------------------------------------------------------------------
:method size
return words(index)
:*------------------------------------------------------------------
:* add an item to the set
:*------------------------------------------------------------------
:method add
value = arg(1)
pos = position(value)
if (0 <> pos) then
return self
max = max + 1
item.max = value
index = index max
rc = RoxAddVar(self,"item."max)
return self
/*------------------------------------------------------------------
* find position of the item in item array
*------------------------------------------------------------------*/
position:
value = arg(1)
do i = 1 to words(index)
ind = word(index,i)
if (item.ind = value) then
return ind
end
return 0
:*------------------------------------------------------------------
:* delete an item from the set
:*------------------------------------------------------------------
:method delete
value = arg(1)
pos = position(value)
if (0 = pos) then
return self
drop item.pos
p = wordpos(index,pos)
index = deleteword(index,p)
return self
/*------------------------------------------------------------------
* find position of the item in item array
*------------------------------------------------------------------*/
position:
value = arg(1)
do i = 1 to words(index)
ind = word(index,i)
if (item.ind = value) then
return ind
end
return 0
:*------------------------------------------------------------------
:* return if item in set
:*------------------------------------------------------------------
:method includes
value = arg(1)
if (0 = position(value)) then
return 0
return 1
/*------------------------------------------------------------------
* find position of the item in item array
*------------------------------------------------------------------*/
position:
value = arg(1)
do i = 1 to words(index)
ind = word(index,i)
if (item.ind = value) then
return ind
end
return 0
:*------------------------------------------------------------------
:* return item at a particular position
:*------------------------------------------------------------------
:method atIndex
ind = arg(1)
ind = word(index,ind)
return item.ind