github.com/djordje200179/extendedlibrary/datastructures@v1.7.1-0.20240227175559-d09520a92dd4/cols/bitarray/bitwise_operations.go (about)

     1  package bitarray
     2  
     3  // And performs bitwise AND operation on two arrays and returns the result.
     4  func And(array1, array2 *Array) *Array {
     5  	resArray := array1.Clone()
     6  	resArray.And(array2)
     7  	return resArray
     8  }
     9  
    10  // Or performs bitwise OR operation on two arrays and returns the result.
    11  func Or(array1, array2 *Array) *Array {
    12  	resArray := array1.Clone()
    13  	resArray.Or(array2)
    14  	return resArray
    15  }
    16  
    17  // Xor performs bitwise XOR operation on two arrays and returns the result.
    18  func Xor(array1, array2 *Array) *Array {
    19  	resArray := array1.Clone()
    20  	resArray.Xor(array2)
    21  	return resArray
    22  }
    23  
    24  // Not performs bitwise NOT operation on an array and returns the result.
    25  func Not(array *Array) *Array {
    26  	result := array.Clone()
    27  	result.FlipAll()
    28  	return result
    29  }
    30  
    31  // ShiftLeft performs bitwise left shift operation on an array and returns the result.
    32  func ShiftLeft(array *Array, operationType ShiftType) *Array {
    33  	result := array.Clone()
    34  	result.ShiftLeft(operationType)
    35  	return result
    36  }
    37  
    38  // ShiftRight performs bitwise right shift operation on an array and returns the result.
    39  func ShiftRight(array *Array, operationType ShiftType) *Array {
    40  	result := array.Clone()
    41  	result.ShiftRight(operationType)
    42  	return result
    43  }