Class: BitVector
- Inherits:
-
Object
- Object
- BitVector
- Includes:
- Comparable
- Defined in:
- lib/bit_vector/version.rb,
ext/bit_vector/bit_vector.c
Constant Summary collapse
- VERSION =
0.9
Class Method Summary collapse
Instance Method Summary collapse
- #&(other) ⇒ Object
- #*(other) ⇒ Object
- #+(other) ⇒ Object
-
#-(other) ⇒ Object
r = a and ~b.
- #<=>(other) ⇒ Object
- #[](vidx) ⇒ Object
- #[]=(vidx, vobj) ⇒ Object
- #^(other) ⇒ Object
- #bytesize ⇒ Object
- #clear ⇒ Object
- #clone ⇒ Object
- #count ⇒ Object
- #dup ⇒ Object
- #each ⇒ Object
- #get(vidx) ⇒ Object
-
#index(vobj, voff) ⇒ Object
This method returns the index of the first bit set to the given value.
- #length ⇒ Object
- #max ⇒ Object
- #min ⇒ Object
- #nonzero? ⇒ Boolean
- #normalize ⇒ Object
- #normalize! ⇒ Object
- #off(*args) ⇒ Object
- #on(*args) ⇒ Object
- #set(vidx, vobj) ⇒ Object
- #size ⇒ Object
- #size=(obj) ⇒ Object
-
#slice(vidx) ⇒ Object
This method extracts a subset of the bit_vector.
- #to_ary ⇒ Object
- #to_bytes ⇒ Object
- #to_s ⇒ Object
- #zero? ⇒ Boolean
- #|(other) ⇒ Object
- #~ ⇒ Object
Class Method Details
.from_bytes(arg) ⇒ Object
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 |
# File 'ext/bit_vector/bit_vector.c', line 437
static VALUE bits_s_from_bytes(VALUE self, VALUE arg) {
struct BitVector *bits;
VALUE retobj;
int64_t len;
Check_Type(arg, T_STRING);
len = RSTRING_LEN(arg);
if (len<1) {
rb_raise(rb_eArgError, "array size");
}
retobj = Data_Make_Struct(self, struct BitVector, NULL, bits_free, bits);
BITCOUNTS(bits, len*8);
bits->ptr = ALLOC_N(uint64_t, bits->qws_len);
memcpy(bits->ptr, RSTRING_PTR(arg), len);
return retobj;
}
|
.new(*args) ⇒ Object
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 |
# File 'ext/bit_vector/bit_vector.c', line 361
static VALUE bits_s_new(int argc, VALUE *argv, VALUE self) {
struct BitVector *bits;
VALUE arg;
VALUE obj;
int bitcnt;
int64_t len;
uint64_t qw, *bptr;
unsigned char *ptr;
obj = Data_Make_Struct(self, struct BitVector, NULL, bits_free, bits);
switch(argc) {
case 0:
arg = INT2FIX(1);
break;
case 1:
arg = argv[0];
break;
default:
arg = INT2FIX(0);
rb_raise(rb_eArgError, "Too many args");
}
switch(TYPE(arg)) {
case T_FIXNUM:
BITCOUNTS(bits, FIX2LONG(arg));
if (bits->bit_len < 1) {
rb_raise(rb_eArgError, "May not be less than one");
}
bits->ptr = ALLOC_N(uint64_t, bits->qws_len);
memset(bits->ptr, 0, bits->qws_len*8);
break;
case T_STRING:
len = RSTRING_LEN(arg);
BITCOUNTS(bits,len);
bits->ptr = ALLOC_N(uint64_t, bits->qws_len);
memset(bits->ptr, 0, bits->qws_len*8);
qw = 0;
bitcnt = 0;
ptr = (unsigned char *)RSTRING_PTR(arg);
bptr = bits->ptr;
while(len--) {
switch(*ptr++) {
case '0':
case '-':
case 'f':
case 'F':
case 'N':
break;
default:
__asm ( "bts %1, %0" : "=g"(qw) : "r"(bitcnt) : "cc","memory");
}
bitcnt++;
if (bitcnt == 64) {
*bptr++ = qw;
qw = 0;
bitcnt = 0;
}
}
if (bitcnt) {
*bptr++ = qw;
}
break;
default:
rb_raise(rb_eArgError, "not valid value");
}
return obj;
}
|
Instance Method Details
#&(other) ⇒ Object
692 693 694 695 696 697 698 699 700 701 702 703 704 |
# File 'ext/bit_vector/bit_vector.c', line 692
static VALUE bits_and(VALUE self, VALUE other) {
VALUE r;
struct BitVector *rbits, *xbits, *ybits;
Data_Get_Struct(self, struct BitVector, xbits);
Data_Get_Struct(other, struct BitVector, ybits);
r = Data_Make_Struct(CLASS_OF(self), struct BitVector, NULL, bits_free, rbits);
bs_and(rbits, xbits, ybits);
return r;
}
|
#*(other) ⇒ Object
692 693 694 695 696 697 698 699 700 701 702 703 704 |
# File 'ext/bit_vector/bit_vector.c', line 692
static VALUE bits_and(VALUE self, VALUE other) {
VALUE r;
struct BitVector *rbits, *xbits, *ybits;
Data_Get_Struct(self, struct BitVector, xbits);
Data_Get_Struct(other, struct BitVector, ybits);
r = Data_Make_Struct(CLASS_OF(self), struct BitVector, NULL, bits_free, rbits);
bs_and(rbits, xbits, ybits);
return r;
}
|
#+(other) ⇒ Object
659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 |
# File 'ext/bit_vector/bit_vector.c', line 659
static VALUE bits_or(VALUE self, VALUE other) {
VALUE obj;
struct BitVector *bits, *rbits, *xbits;
Data_Get_Struct(self, struct BitVector, bits);
obj = Data_Make_Struct(CLASS_OF(self), struct BitVector, NULL, bits_free, rbits);
*rbits = *bits;
rbits->ptr = ALLOC_N(uint64_t, rbits->qws_len);
memcpy(rbits->ptr, bits->ptr, rbits->qws_len*8);
Data_Get_Struct(other, struct BitVector, xbits);
bs_or(rbits, xbits);
return obj;
}
|
#-(other) ⇒ Object
r = a and ~b
724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 |
# File 'ext/bit_vector/bit_vector.c', line 724
static VALUE bits_minus(VALUE self, VALUE other) {
VALUE r;
struct BitVector i;
struct BitVector *rbits, *xbits, *ybits, *ibits;
Data_Get_Struct(self, struct BitVector, xbits);
Data_Get_Struct(other, struct BitVector, ybits);
r = Data_Make_Struct(CLASS_OF(self), struct BitVector, NULL, bits_free, rbits);
ibits = &i;
*ibits = *ybits;
ibits->ptr = ALLOC_N(uint64_t, ibits->qws_len);
memcpy(ibits->ptr, ybits->ptr, ibits->qws_len*8);
if (xbits->bit_len > ybits->bit_len) bs_resize(ibits, xbits->bit_len);
bs_not(ibits);
bs_and(rbits, xbits, ibits);
return r;
}
|
#<=>(other) ⇒ Object
745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 |
# File 'ext/bit_vector/bit_vector.c', line 745
static VALUE bits_cmp(VALUE self, VALUE other) {
struct BitVector *sbits, *obits;
int64_t smax,omax,qws;
uint64_t *sptr,*optr, sqw, oqw;
Data_Get_Struct(self, struct BitVector, sbits);
Data_Get_Struct(other, struct BitVector, obits);
smax = bs_max(sbits);
omax = bs_max(obits);
if (smax < omax) {
return INT2FIX(-1);
} else if (smax > omax) {
return INT2FIX(1);
}
if (smax < 0) {
return INT2FIX(0);
}
qws = (smax+63)/64;
sptr = sbits->ptr + qws - 1;
optr = obits->ptr + qws - 1;
while(qws--) {
sqw = *sptr--;
oqw = *optr--;
if (sqw < oqw) {
return INT2FIX(-1);
} else if (sqw > oqw) {
return INT2FIX(1);
}
}
return INT2FIX(0);
}
|
#[](vidx) ⇒ Object
532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 |
# File 'ext/bit_vector/bit_vector.c', line 532
static VALUE bits_get(VALUE self, VALUE vidx) {
struct BitVector *bits;
int64_t index;
int bit;
Data_Get_Struct(self, struct BitVector, bits);
Check_Type(vidx, T_FIXNUM);
index = FIX2LONG(vidx);
if (index<0) {
rb_raise(rb_eRangeError, "index range");
}
bit = bs_get(bits, index);
return INT2FIX(bit);
}
|
#[]=(vidx, vobj) ⇒ Object
552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 |
# File 'ext/bit_vector/bit_vector.c', line 552
static VALUE bits_set(VALUE self, VALUE vidx, VALUE vobj) {
struct BitVector *bits;
int64_t index;
int bit;
Data_Get_Struct(self, struct BitVector, bits);
Check_Type(vidx, T_FIXNUM);
index = FIX2LONG(vidx);
if (index<0) {
rb_raise(rb_eRangeError, "index range");
}
bit = to_bit(vobj);
bs_set(bits, index, bit);
return self;
}
|
#^(other) ⇒ Object
706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 |
# File 'ext/bit_vector/bit_vector.c', line 706
static VALUE bits_xor(VALUE self, VALUE other) {
VALUE obj;
struct BitVector *bits, *rbits, *xbits;
Data_Get_Struct(self, struct BitVector, bits);
obj = Data_Make_Struct(CLASS_OF(self), struct BitVector, NULL, bits_free, rbits);
*rbits = *bits;
rbits->ptr = ALLOC_N(uint64_t, rbits->qws_len);
memcpy(rbits->ptr, bits->ptr, rbits->qws_len*8);
Data_Get_Struct(other, struct BitVector, xbits);
bs_xor(rbits, xbits);
return obj;
}
|
#bytesize ⇒ Object
467 468 469 470 471 472 473 |
# File 'ext/bit_vector/bit_vector.c', line 467
static VALUE bits_bytesize(VALUE self) {
struct BitVector *bits;
Data_Get_Struct(self, struct BitVector, bits);
return LONG2FIX(bs_bytesize(bits));
}
|
#clear ⇒ Object
523 524 525 526 527 528 529 530 |
# File 'ext/bit_vector/bit_vector.c', line 523
static VALUE bits_clear(VALUE self) {
struct BitVector *bits;
Data_Get_Struct(self, struct BitVector, bits);
memset(bits->ptr, 0, bits->qws_len*8);
return self;
}
|
#clone ⇒ Object
508 509 510 511 512 513 514 515 516 517 518 519 520 521 |
# File 'ext/bit_vector/bit_vector.c', line 508
static VALUE bits_dup(VALUE self) {
struct BitVector *orig;
struct BitVector *dups;
VALUE obj;
Data_Get_Struct(self, struct BitVector, orig);
obj = Data_Make_Struct(CLASS_OF(self), struct BitVector, NULL, bits_free, dups);
*dups = *orig;
dups->ptr = ALLOC_N(uint64_t, dups->qws_len);
memcpy(dups->ptr, orig->ptr, dups->qws_len*8);
return obj;
}
|
#count ⇒ Object
942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 |
# File 'ext/bit_vector/bit_vector.c', line 942
static VALUE bits_count(VALUE self) {
struct BitVector *bits;
uint64_t *ptr, qw;
int64_t count;
int64_t i;
Data_Get_Struct(self, struct BitVector, bits);
count = 0;
ptr = bits->ptr;
for(i = 0 ; i < bits->qws_len; i++) {
qw = *ptr++;
__asm ( "mov %1, %%r8 \n"
"bs_count: \n"
"bsf %%r8, %%r11 \n"
"jz bs_count_exit \n"
"inc %0 \n"
"btr %%r11, %%r8 \n"
"jmp bs_count \n"
"bs_count_exit: \n"
: "=&r"(count) : "r"(qw) : "%r8", "cc", "memory"
);
}
return LONG2FIX(count);
}
|
#dup ⇒ Object
508 509 510 511 512 513 514 515 516 517 518 519 520 521 |
# File 'ext/bit_vector/bit_vector.c', line 508
static VALUE bits_dup(VALUE self) {
struct BitVector *orig;
struct BitVector *dups;
VALUE obj;
Data_Get_Struct(self, struct BitVector, orig);
obj = Data_Make_Struct(CLASS_OF(self), struct BitVector, NULL, bits_free, dups);
*dups = *orig;
dups->ptr = ALLOC_N(uint64_t, dups->qws_len);
memcpy(dups->ptr, orig->ptr, dups->qws_len*8);
return obj;
}
|
#each ⇒ Object
927 928 929 930 931 932 933 934 935 936 937 938 939 940 |
# File 'ext/bit_vector/bit_vector.c', line 927
static VALUE bits_each(VALUE self) {
struct BitVector *bits;
int64_t idx;
Data_Get_Struct(self, struct BitVector, bits);
for(idx=0; idx < bits->bit_len; idx++) {
if (bs_get(bits, idx)) {
rb_yield(LONG2FIX(idx));
}
}
return self;
}
|
#get(vidx) ⇒ Object
532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 |
# File 'ext/bit_vector/bit_vector.c', line 532
static VALUE bits_get(VALUE self, VALUE vidx) {
struct BitVector *bits;
int64_t index;
int bit;
Data_Get_Struct(self, struct BitVector, bits);
Check_Type(vidx, T_FIXNUM);
index = FIX2LONG(vidx);
if (index<0) {
rb_raise(rb_eRangeError, "index range");
}
bit = bs_get(bits, index);
return INT2FIX(bit);
}
|
#index(vobj, voff) ⇒ Object
This method returns the index of the first bit set to the given value
575 576 577 578 579 580 581 582 583 584 585 586 587 588 |
# File 'ext/bit_vector/bit_vector.c', line 575
static VALUE bits_index(VALUE self, VALUE vobj, VALUE voff) {
struct BitVector *bits;
int64_t pos, off;
int bit;
Data_Get_Struct(self, struct BitVector, bits);
bit = to_bit(vobj);
Check_Type(voff, T_FIXNUM);
off = FIX2LONG(voff);
pos = bs_index(bits, bit, off);
return (pos == -1) ? Qnil : LONG2FIX(pos);
}
|
#length ⇒ Object
459 460 461 462 463 464 465 |
# File 'ext/bit_vector/bit_vector.c', line 459
static VALUE bits_length(VALUE self) {
struct BitVector *bits;
Data_Get_Struct(self, struct BitVector, bits);
return LONG2FIX(bits->bit_len);
}
|
#max ⇒ Object
816 817 818 819 820 821 822 823 824 825 826 827 828 829 |
# File 'ext/bit_vector/bit_vector.c', line 816
static VALUE bits_max(VALUE self) {
struct BitVector *bits;
int64_t index;
Data_Get_Struct(self, struct BitVector, bits);
index = bs_max(bits);
if (index >= 0) {
return LONG2FIX(index);
} else {
return Qnil;
}
}
|
#min ⇒ Object
831 832 833 834 835 836 837 838 839 840 841 842 843 844 |
# File 'ext/bit_vector/bit_vector.c', line 831
static VALUE bits_min(VALUE self) {
struct BitVector *bits;
int64_t index;
Data_Get_Struct(self, struct BitVector, bits);
index = bs_min(bits);
if (index >= 0) {
return LONG2FIX(index);
} else {
return Qnil;
}
}
|
#nonzero? ⇒ Boolean
799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 |
# File 'ext/bit_vector/bit_vector.c', line 799
static VALUE bits_nonzero(VALUE self) {
struct BitVector *bits;
uint64_t *ptr;
int64_t i;
Data_Get_Struct(self, struct BitVector, bits);
ptr = bits->ptr;
for(i=0 ; i<bits->qws_len; i++) {
if (*ptr++ != 0) {
return Qtrue;
}
}
return Qfalse;
}
|
#normalize ⇒ Object
846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 |
# File 'ext/bit_vector/bit_vector.c', line 846
static VALUE bits_norm(VALUE self) {
VALUE obj;
struct BitVector *bits;
int64_t index;
obj = bits_dup(self);
Data_Get_Struct(obj, struct BitVector, bits);
index = bs_max(bits);
if (index < 0) {
index = 1;
} else {
index = index + 1;
}
bs_resize(bits, index);
return obj;
}
|
#normalize! ⇒ Object
865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 |
# File 'ext/bit_vector/bit_vector.c', line 865
static VALUE bits_normx(VALUE self) {
struct BitVector *bits;
int64_t index;
Data_Get_Struct(self, struct BitVector, bits);
index = bs_max(bits);
if (index < 0) {
index = 1;
} else {
index = index + 1;
}
bs_resize(bits, index);
return self;
}
|
#off(*args) ⇒ Object
646 647 648 649 650 651 652 653 654 655 656 657 |
# File 'ext/bit_vector/bit_vector.c', line 646
static VALUE bits_off(int argc, VALUE *argv, VALUE self) {
struct BitVector *bits;
int i;
Data_Get_Struct(self, struct BitVector, bits);
for(i=0; i<argc; i++) {
bs_fill(argv[i], bits, 0);
}
return self;
}
|
#on(*args) ⇒ Object
634 635 636 637 638 639 640 641 642 643 644 |
# File 'ext/bit_vector/bit_vector.c', line 634
static VALUE bits_on(int argc, VALUE *argv, VALUE self) {
struct BitVector *bits;
int i;
Data_Get_Struct(self, struct BitVector, bits);
for(i=0; i<argc; i++) {
bs_fill(argv[i], bits, 1);
}
return self;
}
|
#set(vidx, vobj) ⇒ Object
552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 |
# File 'ext/bit_vector/bit_vector.c', line 552
static VALUE bits_set(VALUE self, VALUE vidx, VALUE vobj) {
struct BitVector *bits;
int64_t index;
int bit;
Data_Get_Struct(self, struct BitVector, bits);
Check_Type(vidx, T_FIXNUM);
index = FIX2LONG(vidx);
if (index<0) {
rb_raise(rb_eRangeError, "index range");
}
bit = to_bit(vobj);
bs_set(bits, index, bit);
return self;
}
|
#size ⇒ Object
459 460 461 462 463 464 465 |
# File 'ext/bit_vector/bit_vector.c', line 459
static VALUE bits_length(VALUE self) {
struct BitVector *bits;
Data_Get_Struct(self, struct BitVector, bits);
return LONG2FIX(bits->bit_len);
}
|
#size=(obj) ⇒ Object
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 |
# File 'ext/bit_vector/bit_vector.c', line 475
static VALUE bits_resize(VALUE self, VALUE obj) {
struct BitVector *bits;
int64_t len;
Check_Type(obj, T_FIXNUM);
len = FIX2LONG(obj);
if (len<1) {
rb_raise(rb_eArgError, "array size");
}
Data_Get_Struct(self, struct BitVector, bits);
bs_resize(bits, len);
return self;
}
|
#slice(vidx) ⇒ Object
This method extracts a subset of the bit_vector
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 |
# File 'ext/bit_vector/bit_vector.c', line 591
static VALUE bits_slice(VALUE self, VALUE vidx) {
struct BitVector *bits;
struct BitVector *slis;
VALUE obj;
VALUE vfirst, vend;
int64_t first = 0, end = 0;
int64_t ix, ox;
Data_Get_Struct(self, struct BitVector, bits);
/* Validate the range and extract start and end */
if (rb_class_of(vidx)==rb_cRange) {
vfirst = rb_funcall(vidx, id_first, 0);
vend = rb_funcall(vidx, id_end, 0);
Check_Type(vfirst, T_FIXNUM);
Check_Type(vend, T_FIXNUM);
first = FIX2LONG(vfirst);
end = FIX2LONG(vend);
if (rb_funcall(vidx, rb_intern("exclude_end?"), 0) == Qtrue) {
end--;
}
if (first>end || first<0 || end<0) {
rb_raise(rb_eRangeError, "not valid range");
}
} else {
rb_raise(rb_eTypeError, "not valid index");
}
obj = Data_Make_Struct(CLASS_OF(self), struct BitVector, NULL, bits_free, slis);
slis->bit_len = end - first + 1;
slis->qws_len = (slis->bit_len+63)/64;
slis->last_bit = slis->bit_len % 64;
slis->ptr = ALLOC_N(uint64_t, slis->qws_len);
/* Now copy the bits TBD use __asm */
for (ix = first, ox = 0; ix <= end; ix++,ox++) {
bs_set(slis, ox, bs_get(bits, ix));
}
return obj;
}
|
#to_ary ⇒ Object
883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 |
# File 'ext/bit_vector/bit_vector.c', line 883
static VALUE bits_to_ary(VALUE self) {
VALUE ary;
struct BitVector *bits;
int64_t from, to, index;
Data_Get_Struct(self, struct BitVector, bits);
ary = rb_ary_new();
for (index = 0; index != -1;) {
index = bs_index(bits, 1, index);
if (index < 0) break;
from = index;
to = from;
do {
index = bs_index(bits, 1, index+1);
if (index == -1) break;
if (index == to + 1) to = index;
} while (index == to);
if (from==to) {
rb_ary_push(ary, LONG2FIX(from));
} else {
rb_ary_push(ary, rb_funcall(rb_cRange, id_new, 2, LONG2FIX(from), LONG2FIX(to)));
}
}
return ary;
}
|
#to_bytes ⇒ Object
912 913 914 915 916 917 918 919 920 921 922 923 924 925 |
# File 'ext/bit_vector/bit_vector.c', line 912
static VALUE bits_to_bytes(VALUE self) {
struct BitVector *bits;
VALUE rs;
Data_Get_Struct(self, struct BitVector, bits);
int64_t len = bs_bytesize(bits);
rs = rb_str_new(0, len);
memcpy(RSTRING_PTR(rs), bits->ptr, len);
return rs;
}
|
#to_s ⇒ Object
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 |
# File 'ext/bit_vector/bit_vector.c', line 491
static VALUE bits_to_s(VALUE self) {
struct BitVector *bits;
unsigned char *ptr;
int64_t i;
VALUE str;
Data_Get_Struct(self, struct BitVector, bits);
str = rb_str_new(0, bits->bit_len);
ptr = (unsigned char *)RSTRING_PTR(str);
for(i=0; i<bits->bit_len; i++) {
*ptr++ = bs_get(bits, i) ? '1' : '0';
}
return str;
}
|
#zero? ⇒ Boolean
782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 |
# File 'ext/bit_vector/bit_vector.c', line 782
static VALUE bits_zero(VALUE self) {
struct BitVector *bits;
uint64_t *ptr;
int64_t i;
Data_Get_Struct(self, struct BitVector, bits);
ptr = bits->ptr;
for(i=0 ; i<bits->qws_len; i++) {
if (*ptr++ != 0) {
return Qfalse;
}
}
return Qtrue;
}
|
#|(other) ⇒ Object
659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 |
# File 'ext/bit_vector/bit_vector.c', line 659
static VALUE bits_or(VALUE self, VALUE other) {
VALUE obj;
struct BitVector *bits, *rbits, *xbits;
Data_Get_Struct(self, struct BitVector, bits);
obj = Data_Make_Struct(CLASS_OF(self), struct BitVector, NULL, bits_free, rbits);
*rbits = *bits;
rbits->ptr = ALLOC_N(uint64_t, rbits->qws_len);
memcpy(rbits->ptr, bits->ptr, rbits->qws_len*8);
Data_Get_Struct(other, struct BitVector, xbits);
bs_or(rbits, xbits);
return obj;
}
|
#~ ⇒ Object
676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 |
# File 'ext/bit_vector/bit_vector.c', line 676
static VALUE bits_not(VALUE self) {
VALUE obj;
struct BitVector *bits, *rbits;
Data_Get_Struct(self, struct BitVector, bits);
obj = Data_Make_Struct(CLASS_OF(self), struct BitVector, NULL, bits_free, rbits);
*rbits = *bits;
rbits->ptr = ALLOC_N(uint64_t, rbits->qws_len);
memcpy(rbits->ptr, bits->ptr, rbits->qws_len*8);
bs_not(rbits);
return obj;
}
|