home *** CD-ROM | disk | FTP | other *** search
- \
- \ SETS IN VECTOR REPRESENTATION
- \
- \ Copyright (C) 1990 by Mikael R.K. Patel
- \
- \ Computer Aided Design Laboratory (CADLAB)
- \ Department of Computer and Information Science
- \ Linkoping University
- \ S-581 83 LINKOPING
- \ SWEDEN
- \
- \ Email: mip@ida.liu.se
- \
- \ Started on: 1 May 1990
- \
- \ Last updated on: 7 August 1990
- \
- \ Dependencies:
- \ (forth) forth, blocks
- \
- \ Description:
- \ Management of sets represented as a vector of cells. The set
- \ is terminated by the value zero (nil). Thus zero cannot be
- \ a member of a set. Used mainly for sets of entries. The tile
- \ forth vocabulary search path, "context", is defined as a set
- \ of vocabulary entry pointers.
- \
- \ Copying:
- \ This program is free software; you can redistribute it and\or modify
- \ it under the terms of the GNU General Public License as published by
- \ the Free Software Foundation; either version 1, or (at your option)
- \ any later version.
- \
- \ This program is distributed in the hope that it will be useful,
- \ but WITHOUT ANY WARRANTY; without even the implied warranty of
- \ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- \ GNU General Public License for more details.
- \
- \ You should have received a copy of the GNU General Public License
- \ along with this program; see the file COPYING. If not, write to
- \ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
-
- .( Loading Sets definitions...) cr
-
- #include blocks.f83
-
- vocabulary sets ( -- )
-
- blocks sets definitions
-
- : set ( size -- )
- create nil here ! cells allot
- ;
-
- : { ( -- )
- align here ]
- ; execution
-
- : } ( -- set)
- nil , [compile] [
- ; immediate
-
- : empty-set ( set -- )
- nil swap !
- ;
-
- : search-set ( element set -- [addr1] or [element addr2 false])
- swap >r
- begin
- dup @ ?dup
- while
- r@ =
- if r> drop exit then
- cell+
- repeat
- r> swap false
- ; private
-
- : add-set ( element set -- )
- search-set boolean not if nil over cell+ ! ! then
- ;
-
- : remove-set ( element set -- )
- search-set ?dup
- if
- begin
- dup cell+ tuck
- @ dup 0= >r swap ! r>
- until
- drop
- else
- 2drop
- then
- ;
-
- : size-set ( set -- num)
- 0 swap
- begin
- dup @
- while
- swap 1+ swap cell+
- repeat
- drop
- ;
-
- : map-set ( set block[element -- ] -- )
- >r
- begin
- dup @ ?dup
- while
- r@ rot >r
- call
- r> cell+
- repeat
- r> 2drop
- ;
-
- : ?map-set ( set block[element -- bool] -- )
- >r
- begin
- dup @ ?dup
- while
- r@ rot >r
- call
- if 2r> 2drop exit then
- r> cell+
- repeat
- r> 2drop
- ;
-
- : union-set ( set1 set2 -- )
- >r
- begin
- dup @ ?dup
- while
- r@ add-set cell+
- repeat
- r> 2drop
- ;
-
- : intersection-set ( set1 set2 -- )
- swap >r
- begin
- dup @ ?dup
- while
- r@ search-set
- if cell+
- else
- 2drop dup
- begin
- dup cell+ tuck
- @ dup 0= >r swap ! r>
- until
- drop
- then
- repeat
- r> 2drop
- ;
-
- : apply-set ( set -- )
- begin
- dup @ ?dup
- while
- execute cell+
- repeat
- drop
- ;
-
- : ?member-set ( element set -- bool)
- search-set if true else 2drop false then
- ;
-
- : ?empty-set ( set -- bool)
- @ 0=
- ;
-
- : .set ( set -- )
- ." { "
- block[ ( entry -- ) .name space ]; map-set
- ." } "
- ;
-
- forth only
-