package org.btcollider.cnc.dto;

import java.util.BitSet;

import org.btcollider.cnc.CnC;

public class KeyRange {
	private Long start;
	private Long end;

	public KeyRange(BitSet start, BitSet end) {
		assert start.length() <= CnC.MAX_BITS && end.length() <= CnC.MAX_BITS;

		this.start = start.toLongArray()[0];
		this.end = end.toLongArray()[0];
	}
	
	public KeyRange(Long start, Long end) {
		this.start = start;
		this.end = end;
	}
	
	public Long getStart() {
		return start;
	}

	public Long getEnd() {
		return end;
	}

	public Long getTotal() {
		// asserted that <= MAX_BITS, first long contains all significant bits
		Long total = getEnd() - getStart() + 1; // +1 bc start is included too

		return total;
	}

	@Override
	public String toString() {
		return "KeyRange [start=" + start + ", end=" + end + ", total=" + getTotal() +"]";
	}
}
