Skip to content

Commit

Permalink
Rename assign to copy_from.
Browse files Browse the repository at this point in the history
  • Loading branch information
plietar committed Jul 16, 2024
1 parent eb921bb commit cd8036e
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 38 deletions.
4 changes: 2 additions & 2 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ bitset_or <- function(a, b) {
invisible(.Call(`_individual_bitset_or`, a, b))
}

bitset_assign <- function(a, b) {
invisible(.Call(`_individual_bitset_assign`, a, b))
bitset_copy_from <- function(a, b) {
invisible(.Call(`_individual_bitset_copy_from`, a, b))
}

bitset_xor <- function(a, b) {
Expand Down
27 changes: 15 additions & 12 deletions R/bitset.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,6 @@ Bitset <- list(
self
},

#' ```{r echo=FALSE, results="asis"}
#' bitset_method_doc(
#' "assign",
#' "overwrite the value of a bitset from another bitset",
#' other = "the other bitset.")
#' ```
assign = function(other) {
bitset_assign(self$.bitset, other$.bitset)
self
},

#' ```{r echo=FALSE, results="asis"}
#' bitset_method_doc(
#' "size",
Expand Down Expand Up @@ -221,10 +210,24 @@ Bitset <- list(
#' ```{r echo=FALSE, results="asis"}
#' bitset_method_doc(
#' "copy",
#' "returns a copy of the bitset.")
#' "returns a copy of the bitset. In cases where a destination
#' bitset already exists, it may be more performant to use
#' the \\code{$copy_from} method instead.")
#' ```
copy = function() Bitset$new(from = bitset_copy(self$.bitset)),


#' ```{r echo=FALSE, results="asis"}
#' bitset_method_doc(
#' "copy_from",
#' "overwrite the value of a bitset from another bitset",
#' other = "the other bitset.")
#' ```
copy_from = function(other) {
bitset_copy_from(self$.bitset, other$.bitset)
self
},

#' ```{r echo=FALSE, results="asis"}
#' bitset_method_doc(
#' "to_vector",
Expand Down
28 changes: 15 additions & 13 deletions man/Bitset.Rd

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

4 changes: 3 additions & 1 deletion man/restore_object_state.Rd

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

10 changes: 5 additions & 5 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@ BEGIN_RCPP
return R_NilValue;
END_RCPP
}
// bitset_assign
void bitset_assign(const Rcpp::XPtr<individual_index_t> a, const Rcpp::XPtr<individual_index_t> b);
RcppExport SEXP _individual_bitset_assign(SEXP aSEXP, SEXP bSEXP) {
// bitset_copy_from
void bitset_copy_from(const Rcpp::XPtr<individual_index_t> a, const Rcpp::XPtr<individual_index_t> b);
RcppExport SEXP _individual_bitset_copy_from(SEXP aSEXP, SEXP bSEXP) {
BEGIN_RCPP
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< const Rcpp::XPtr<individual_index_t> >::type a(aSEXP);
Rcpp::traits::input_parameter< const Rcpp::XPtr<individual_index_t> >::type b(bSEXP);
bitset_assign(a, b);
bitset_copy_from(a, b);
return R_NilValue;
END_RCPP
}
Expand Down Expand Up @@ -1475,7 +1475,7 @@ static const R_CallMethodDef CallEntries[] = {
{"_individual_bitset_and", (DL_FUNC) &_individual_bitset_and, 2},
{"_individual_bitset_not", (DL_FUNC) &_individual_bitset_not, 2},
{"_individual_bitset_or", (DL_FUNC) &_individual_bitset_or, 2},
{"_individual_bitset_assign", (DL_FUNC) &_individual_bitset_assign, 2},
{"_individual_bitset_copy_from", (DL_FUNC) &_individual_bitset_copy_from, 2},
{"_individual_bitset_xor", (DL_FUNC) &_individual_bitset_xor, 2},
{"_individual_bitset_set_difference", (DL_FUNC) &_individual_bitset_set_difference, 2},
{"_individual_bitset_sample", (DL_FUNC) &_individual_bitset_sample, 2},
Expand Down
2 changes: 1 addition & 1 deletion src/bitset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void bitset_or(
}

//[[Rcpp::export]]
void bitset_assign(
void bitset_copy_from(
const Rcpp::XPtr<individual_index_t> a,
const Rcpp::XPtr<individual_index_t> b
) {
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-bitset.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ test_that("bitset or works", {
expect_equal(a$to_vector(), c(1, 3, 5, 6, 7))
})

test_that("bitset assign works", {
test_that("bitset copy from works", {
a <- Bitset$new(10)
a$insert(c(1, 5, 6))
b <- Bitset$new(10)
b$insert(c(1, 3, 7))

a$assign(b)
a$copy_from(b)
expect_equal(a$to_vector(), c(1, 3, 7))

# Check the two bitsets aren't aliases of each other.
Expand All @@ -95,13 +95,13 @@ test_that("bitset assign works", {
expect_equal(b$to_vector(), numeric(0))
})

test_that("bitset assign requires bitsets to have same max size", {
test_that("bitset copy from requires bitsets to have same max size", {
a <- Bitset$new(8)
a$insert(c(1, 5, 6))
b <- Bitset$new(10)
b$insert(c(1, 3, 7))

expect_error(a$assign(b), "Incompatible bitmap sizes")
expect_error(a$copy_from(b), "Incompatible bitmap sizes")
})


Expand Down

0 comments on commit cd8036e

Please sign in to comment.