Skip to content

Commit

Permalink
Split documentation blocks into multiple lines
Browse files Browse the repository at this point in the history
  • Loading branch information
plietar committed Feb 27, 2024
1 parent 425f103 commit 08d8760
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 23 deletions.
106 changes: 90 additions & 16 deletions R/bitset.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ bitset_method_doc <- function(name, description, ...) {
}
push("}")

Check warning on line 30 in R/bitset.R

View check run for this annotation

Codecov / codecov/patch

R/bitset.R#L30

Added line #L30 was not covered by tests

paste(lines, collapse="\n")
# lines
cat(paste(lines, collapse="\n"))

Check warning on line 32 in R/bitset.R

View check run for this annotation

Codecov / codecov/patch

R/bitset.R#L32

Added line #L32 was not covered by tests
}

#' @title A Bitset Class
Expand All @@ -50,7 +49,15 @@ bitset_method_doc <- function(name, description, ...) {
#' @export
#' @section Methods:
Bitset <- list(
#' `r bitset_method_doc("new", "create a bitset.", size = "the size of the bitset.", from="pointer to an existing IterableBitset to use; if \\code{NULL} make empty bitset, otherwise copy existing bitset.")`
#' ```{r echo=FALSE, results="asis"}
#' bitset_method_doc(
#' "new",
#' "create a bitset.",
#' size = "the size of the bitset.",
#' from = "pointer to an existing IterableBitset to use; if \\code{NULL}
#' make empty bitset, otherwise copy existing bitset."
#' )
#' ```
new = function(size, from = NULL) {
if (is.null(from)) {
bitset <- create_bitset(size)
Expand All @@ -64,57 +71,109 @@ Bitset <- list(
.bitset = bitset,
max_size = max_size,

#' `r bitset_method_doc("insert", "insert into the bitset.", v = "an integer vector of elements to insert.")`
#' ```{r echo=FALSE, results="asis"}
#' bitset_method_doc(
#' "insert",
#' "insert into the bitset.",
#' v = "an integer vector of elements to insert.")
#' ```
insert = function(v) {
bitset_insert(self$.bitset, v)
self
},

#' `r bitset_method_doc("remove", "remove from the bitset.", v = "an integer vector of elements (not indices) to remove.")`
#' ```{r echo=FALSE, results="asis"}
#' bitset_method_doc(
#' "remove",
#' "remove from the bitset.",
#' v = "an integer vector of elements (not indices) to remove.")
#' ```
remove = function(v) {
bitset_remove(self$.bitset, v)
self
},

#' `r bitset_method_doc("clear", "clear the bitset.")`
#' ```{r echo=FALSE, results="asis"}
#' bitset_method_doc(
#' "clear",
#' "clear the bitset.")
#' ```
clear = function() {
bitset_clear(self$.bitset)
self
},

#' `r bitset_method_doc("size", "get the number of elements in the set.")`
#' ```{r echo=FALSE, results="asis"}
#' bitset_method_doc(
#' "size",
#' "get the number of elements in the set.")
#' ```
size = function() bitset_size(self$.bitset),

#' `r bitset_method_doc("or", "to \"bitwise or\" or union two bitsets.", other = "the other bitset.")`
#' ```{r echo=FALSE, results="asis"}
#' bitset_method_doc(
#' "or",
#' "to \"bitwise or\" or union two bitsets.",
#' other = "the other bitset.")
#' ```
or = function(other) {
bitset_or(self$.bitset, other$.bitset)
self
},

#' `r bitset_method_doc("and", "to \"bitwise and\" or intersect two bitsets.", other = "the other bitset.")`
#' ```{r echo=FALSE, results="asis"}
#' bitset_method_doc(
#' "and",
#' "to \"bitwise and\" or intersect two bitsets.",
#' other = "the other bitset.")
#' ```
and = function(other) {
bitset_and(self$.bitset, other$.bitset)
self
},

#' `r bitset_method_doc("not", "to \"bitwise not\" or complement a bitset.", inplace = "whether to overwrite the current bitset, default = TRUE")`
#' ```{r echo=FALSE, results="asis"}
#' bitset_method_doc(
#' "not",
#' "to \"bitwise not\" or complement a bitset.",
#' inplace = "whether to overwrite the current bitset, default = TRUE")
#' ```
not = function(inplace = TRUE) {
Bitset$new(from = bitset_not(self$.bitset, inplace))
},

#' `r bitset_method_doc("xor", "to \"bitwise xor\" get the symmetric difference of two bitset (keep elements in either bitset but not in their intersection).", other = "the other bitset.")`
#' ```{r echo=FALSE, results="asis"}
#' bitset_method_doc(
#' "xor",
#' "to \"bitwise xor\" get the symmetric difference of two bitset
#' (keep elements in either bitset but not in their intersection).",
#' other = "the other bitset.")
#' ```
xor = function(other){
bitset_xor(self$.bitset, other$.bitset)
self
},

#' `r bitset_method_doc("set_difference", "Take the set difference of this bitset with another (keep elements of this bitset which are not in \\code{other})", other = "the other bitset.")`
#' ```{r echo=FALSE, results="asis"}
#' bitset_method_doc(
#' "set_difference",
#' "Take the set difference of this bitset with another
#' (keep elements of this bitset which are not in \\code{other})",
#' other = "the other bitset.")
#' ```
set_difference = function(other){
bitset_set_difference(self$.bitset, other$.bitset)
self
},

#' `r bitset_method_doc("sample", "sample a bitset.", rate = "the success probability for keeping each element, can be a single value for all elements or a vector of unique probabilities for keeping each element.")`
#' ```{r echo=FALSE, results="asis"}
#' bitset_method_doc(
#' "sample",
#' "sample a bitset.",
#' rate = "the success probability for keeping each element, can be
#' a single value for all elements or a vector of unique
#' probabilities for keeping each element.")
#' ```
sample = function(rate) {
stopifnot(is.finite(rate), !is.null(rate))
if (length(rate) == 1) {
Expand All @@ -125,7 +184,14 @@ Bitset <- list(
self
},

#' `r bitset_method_doc("choose", "choose k random items in the bitset.", k = "the number of items in the bitset to keep. The selection of these k items from N total items in the bitset is random, and k should be chosen such that \\eqn{0 \\le k \\le N}.")`
#' ```{r echo=FALSE, results="asis"}
#' bitset_method_doc(
#' "choose",
#' "choose k random items in the bitset.",
#' k = "the number of items in the bitset to keep. The selection of
#' these k items from N total items in the bitset is random, and
#' k should be chosen such that \\eqn{0 \\le k \\le N}.")
#' ```
choose = function(k) {
stopifnot(is.finite(k))
stopifnot(k <= bitset_size(self$.bitset))
Expand All @@ -136,10 +202,18 @@ Bitset <- list(
self
},

#' `r bitset_method_doc("copy", "returns a copy of the bitset.")`
#' ```{r echo=FALSE, results="asis"}
#' bitset_method_doc(
#' "copy",
#' "returns a copy of the bitset.")
#' ```
copy = function() Bitset$new(from = bitset_copy(self$.bitset)),

#' `r bitset_method_doc("to_vector", "return an integer vector of the elements stored in this bitset.")`
#' ```{r echo=FALSE, results="asis"}
#' bitset_method_doc(
#' "to_vector",
#' "return an integer vector of the elements stored in this bitset.")
#' ```
to_vector = function() bitset_to_vector(self$.bitset)
)

Expand Down
20 changes: 13 additions & 7 deletions man/Bitset.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 08d8760

Please sign in to comment.