// Path: src/main/java/com/jordanwilliams/heftydb/util/Sizes.java
// public class Sizes {
// 
//     public static int LONG_SIZE = 8;
// 
//     public static int INT_SIZE = 4;
// }


import com.jordanwilliams.heftydb.util.Sizes;
import java.nio.ByteBuffer;
/*
 * Copyright (c) 2014. Jordan Williams
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.jordanwilliams.heftydb.offheap;



/**
 * An immutable bit set that is backed by off-heap memory.
 */
public class BitSet implements Offheap {

    public static class Builder {

        private final MemoryPointer pointer;
        private final ByteBuffer directBuffer;
        private final int usableBytes;

        public Builder(long bitCount, int paddingBytes) {
            this.usableBytes = memoryOffset(bitCount) + Sizes.LONG_SIZE;
            this.pointer = MemoryAllocator.allocateAndZero(usableBytes + paddingBytes);
            this.directBuffer = pointer.directBuffer();
        }

        public void set(long bitIndex, boolean value) {
            int offset = memoryOffset(bitIndex);

            if (value) {
                //Set
                directBuffer.putLong(offset, directBuffer.getLong(offset) | (1L << bitIndex));
// Path: src/main/java/com/jordanwilliams/heftydb/util/Sizes.java
// public class Sizes {
// 
//     public static int LONG_SIZE = 8;
// 
//     public static int INT_SIZE = 4;
// }


// Path: src/main/java/com/jordanwilliams/heftydb/offheap/BitSet.java
import com.jordanwilliams.heftydb.util.Sizes;
import java.nio.ByteBuffer;

/*
 * Copyright (c) 2014. Jordan Williams
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.jordanwilliams.heftydb.offheap;



/**
 * An immutable bit set that is backed by off-heap memory.
 */
public class BitSet implements Offheap {

    public static class Builder {

        private final MemoryPointer pointer;
        private final ByteBuffer directBuffer;
        private final int usableBytes;

        public Builder(long bitCount, int paddingBytes) {
            this.usableBytes = memoryOffset(bitCount) + Sizes.LONG_SIZE;
            this.pointer = MemoryAllocator.allocateAndZero(usableBytes + paddingBytes);
            this.directBuffer = pointer.directBuffer();
        }

        public void set(long bitIndex, boolean value) {
            int offset = memoryOffset(bitIndex);

            if (value) {
                //Set
                directBuffer.putLong(offset, directBuffer.getLong(offset) | (1L << bitIndex));
            } else {