Skip to content

Commit 7dfc378

Browse files
authored
Merge pull request #269 from tigergraph/DOC-2526-bitwise-accum-ops
DOC-2526-bitwise-accum-ops
2 parents a51ecec + 00589ff commit 7dfc378

File tree

1 file changed

+57
-15
lines changed

1 file changed

+57
-15
lines changed

modules/querying/pages/accumulators.adoc

+57-15
Original file line numberDiff line numberDiff line change
@@ -652,10 +652,7 @@ include::appendix:example$minimal_net/accum_oraccum_results.json[]
652652
[#_bitwiseandaccum_bitwiseoraccum]
653653
=== BitwiseAndAccum / BitwiseOrAccum
654654

655-
The BitwiseAndAccum and BitwiseOrAccum types calculate and store the cumulative result of a series of bitwise boolean operations and store the resulting bit sequences.
656-
The default length for both BitwiseAndAccum and BitwiseOrAccum is 64 bit.
657-
You can specify the length of both types by appending the desired length in angle brackets``<>``.
658-
655+
The BitwiseAndAccum and BitwiseOrAccum types represent fixed-length bit sequences and calculate the cumulative result of a series of bitwise boolean operations and store the resulting sequences.
659656

660657
Fundamental to understanding and using bitwise operations is the knowledge that integers are stored in base-2 representation as a 64-bit sequence of 1s and 0s.
661658
"Bitwise" means that each bit is treated as a separate boolean value, with 1 representing true and 0 representing false.
@@ -664,14 +661,18 @@ Computing the Bitwise `AND` of two numbers A and B means computing the bit seque
664661

665662
==== Declaration
666663

667-
A bitwise accumulator has different declaration syntax depending on its length:
664+
The default length for a bitwise accumulator is 64 bits.
665+
You can specify a different length by appending the desired length in angle brackets``<>`` in the declaration statement:
666+
667+
[,gsql]
668+
----
669+
@@BitwiseOrAccum<100> @visited;
670+
----
668671

669-
* When a bitwise accumulator length is less than or equal to 64 bit, it's assigned using one integer.
670-
The integer is converted to a 64-bit sequence of 1s and 0s.
672+
* When a bitwise accumulator length is less than or equal to 64, it's stored using one 64-bit integer.
671673
Overflow on the left is ignored.
672-
* When a bitwise accumulator length is longer than 64 bit, it's assigned using an array of two integers.
673-
Each integer is converted to a 64-bit sequence of 1s and 0s.
674-
The integer in the second position will take up the first 64 bits from the right of the sequence, and the integer on the left will take up the remaining bits.
674+
* When a bitwise accumulator length is longer than 64, it's stored using an array of multiple integers.
675+
The rightmost (last) integer in the array is for the 64 least significant bits.
675676
Any overflowing bits will be ignored.
676677

677678
For example, if you are declaring an 80-bit BitwiseAndAccum:
@@ -683,27 +684,68 @@ For example, if you are declaring an 80-bit BitwiseAndAccum:
683684
When the two integers are joined together, the 64-bit sequence on the right (456) takes up the 64 bits from the right.
684685
The 64-bit sequence on the left (123) takes up the remaining 16 bits and the overflow on the left is ignored.
685686

686-
The resulting BitwiseAndAccum prints as below:
687-
688-
0000000001111011 (16bits in total) 0000000...000111001000 (64bits in total)
687+
The resulting BitwiseAndAccum is the concatenation of the two bit sequences:
689688

689+
0000000001111011, followed by 0000000...000111001000
690690

691691

692692
==== Accumulation behavior
693693

694694
For BitwiseAndAccum, `+= arg` updates the accumulator's state to be the Bitwise `AND` of the current state and `arg`.
695695
BitwiseOrAccum behaves the same, with the exception that it computes a Bitwise `OR`.
696696

697+
==== Bitwise Comparison and Operators
698+
699+
Because bitwise accumulators have values that are akin to binary integers, they support both comparison operators:
700+
701+
`<`, `>`, `>=`, `\<=`, `==`,`!=`
702+
703+
Examples: Assume AccumA and AccumB are 8-bit accumulators with the following values:
704+
705+
[source]
706+
----
707+
AccumA = 00010001; // decimal 17
708+
AccumB = 00010000; // decimal 16
709+
710+
AccumA == 17 // true
711+
AccumA > AccumB // true
712+
AccumA < AccumB // false
713+
----
714+
715+
They also support bitwise Boolean logic operators.
716+
If an operator acts on two accumuators, the accumulators must have the same type and length.
717+
The operation produces a new accumulator with the same type and length.
718+
719+
.Bitwise logic operators
720+
[cols="1,2"]
721+
|===
722+
|Operator |Description
723+
724+
|`<accum1> & <accum2>`
725+
|Returns a new bitwise accumulator where each bit is the Boolean `AND` of the corresponding bits in `accum1` and `accum2`.
726+
727+
|`<accum1> \|\| <accum2>`
728+
|Returns a new bitwise accumulator where each bit is the Boolean `OR` of the corresponding bits in `accum1` and `accum2`.
729+
730+
|`<accum1> ^ <accum2>`
731+
|Returns a new bitwise accumulator where each bit is the Boolean `XOR` (exclusive OR) of the corresponding bits in `accum1` and `accum2`.
732+
733+
|`~ <accum>`
734+
|Returns a new bitwise accumulator where each bit is the Boolean `NOT` of the corresponding bit in `accum`.
735+
|===
736+
697737
[CAUTION]
698738
====
699739
Bitwise Operations and Negative Integers
700740
701741
Most computer systems represent negative integers using "2's complement" format, where the uppermost bit has special significance. Operations that affect the uppermost bit are crossing the boundary between positive and negative numbers, and vice versa.
702742
====
703743

744+
745+
704746
==== Functions
705-
This is a list of methods of BitwiseAndAccum and BitwiseOrAccum.
706-
If a method returns an `BitwiseAndAccum` or `BitwiseOrAccum`, it returns the same type as the instance that calls the method.
747+
This is a list of object functions of BitwiseAndAccum and BitwiseOrAccum.
748+
If a function returns an `BitwiseAndAccum` or `BitwiseOrAccum`, it returns the same type as the instance that calls the object function.
707749

708750
.Bitwise accumulator functions
709751
|===

0 commit comments

Comments
 (0)