# NOT RUN {
### create a new instance
# you have to define "="
equal <- function(x, y) return(x$key == y$key)
# remember that the elements in the set must have the "key" attribute
# to create a new instance of the class
set <- RSet$new(equal=equal)
# of course you can start to add elements when creating the instance
set <- RSet$new(equal=equal,
list(key=5, val="5"), collapse=list(list(key=3,val="3"), list(key=9,val="9")))
# the following sentence is equivalent to the above
set <- RSet$new(equal=equal,
list(key=5, val="5"), list(key=3,val="3"), list(key=9,val="9"))
# where the three lists are inserted into the set
### immutable methods
set$has(list(key=5, num=10))
# TRUE as it has the key attribute
### mutable methods
set$add(list(key=5, num=10))
# FALSE
set$add(list(key=10, val="10"))
# TRUE
set$delete(list(key=10))
# TRUE and list(key=10, val="10") is removed
# union
another_set <- RSet$new(equal=equal,
list(key=5, val="5"), list(key=11,val="11"))
set$union(another_set)$show()
# intersection
set$intersection(another_set)$show()
# difference
set$difference(another_set)$show()
# subset
set$subset(another_set)
# contains
set$contains(another_set)
# }
Run the code above in your browser using DataLab