## create an empty set and an empty multiset
hset() # equivalent to hset(NULL), as.hset(list()), or hset(list())
hset(generalized = TRUE)
## create set {1,3,4} and multiset {1[2], 3[1], 4[.5]}
hset(c(1,3,4)) # equivalent to hset(c(1,1,3,4)) or hset(c(1,4,3))
hset(c(1,3,4), c(2,1,.5)) # equivalent to hset(c(1,1,3,4), c(1,1,1,.5))
## recursive definition of sets
hset(hset()) # equivalent to hset(list(list()))
hset(list(1, list(1,list()) )) # {{{},1},1}
## check and coerce hset objects
is.hset(hset())
as.hset(list())
# note that hset(hset()) and as.hset(hset()) are not equivalent
## canonical map from sets to multisets, and vice versa
hs <- hset(); is.generalized(hs)
as.generalized(hs); is.generalized(hs)
as.not.generalized(hs); is.generalized(hs)
# note reference semantic of hs
## value and reference semantics
hs <- hset(c(1,3,4))
hsc <- clone.of.hset(hs)
hsc <- union(hsc, hset(c(4,5)))
hsc; hs # value semantic
hsr <- refer.to.hset(hs) # equivalent to: hsr <- hs, or hsr = hs
hsc <- union(hsc, hset(c(4,5)))
hsr; hs # they refer to the same updated object in memory
## information extraction about hset objects
hm <- hset(c(1,4,3), c(2,.5,1), generalized = TRUE)
members(hm)
multiplicities(hm)
size.support(hm)
cardinality(hm)
Run the code above in your browser using DataLab