flip the values in the range [firstOfRange,lastOfRange]
(firstOfRange, lastOfRange int)
| 834 | |
| 835 | // flip the values in the range [firstOfRange,lastOfRange] |
| 836 | func (ac *arrayContainer) inotClose(firstOfRange, lastOfRange int) container { |
| 837 | if firstOfRange > lastOfRange { // unlike add and remove, not uses an inclusive range [firstOfRange,lastOfRange] |
| 838 | return ac |
| 839 | } |
| 840 | // determine the span of array indices to be affected |
| 841 | startIndex := binarySearch(ac.content, uint16(firstOfRange)) |
| 842 | if startIndex < 0 { |
| 843 | startIndex = -startIndex - 1 |
| 844 | } |
| 845 | lastIndex := binarySearch(ac.content, uint16(lastOfRange)) |
| 846 | if lastIndex < 0 { |
| 847 | lastIndex = -lastIndex - 1 - 1 |
| 848 | } |
| 849 | currentValuesInRange := lastIndex - startIndex + 1 |
| 850 | spanToBeFlipped := lastOfRange - firstOfRange + 1 |
| 851 | |
| 852 | newValuesInRange := spanToBeFlipped - currentValuesInRange |
| 853 | buffer := make([]uint16, newValuesInRange) |
| 854 | cardinalityChange := newValuesInRange - currentValuesInRange |
| 855 | newCardinality := len(ac.content) + cardinalityChange |
| 856 | if cardinalityChange > 0 { |
| 857 | if newCardinality > len(ac.content) { |
| 858 | if newCardinality > arrayDefaultMaxSize { |
| 859 | bcRet := ac.toBitmapContainer() |
| 860 | bcRet.inot(firstOfRange, lastOfRange+1) |
| 861 | *ac = *bcRet.toArrayContainer() |
| 862 | return bcRet |
| 863 | } |
| 864 | ac.content = copyOf(ac.content, newCardinality) |
| 865 | } |
| 866 | base := lastIndex + 1 |
| 867 | copy(ac.content[lastIndex+1+cardinalityChange:], ac.content[base:base+len(ac.content)-1-lastIndex]) |
| 868 | ac.negateRange(buffer, startIndex, lastIndex, firstOfRange, lastOfRange+1) |
| 869 | } else { // no expansion needed |
| 870 | ac.negateRange(buffer, startIndex, lastIndex, firstOfRange, lastOfRange+1) |
| 871 | if cardinalityChange < 0 { |
| 872 | for i := startIndex + newValuesInRange; i < newCardinality; i++ { |
| 873 | ac.content[i] = ac.content[i-cardinalityChange] |
| 874 | } |
| 875 | } |
| 876 | } |
| 877 | ac.content = ac.content[:newCardinality] |
| 878 | return ac |
| 879 | } |
| 880 | |
| 881 | func (ac *arrayContainer) negateRange(buffer []uint16, startIndex, lastIndex, startRange, lastRange int) { |
| 882 | // compute the negation into buffer |
no test coverage detected