// Path: src/main/java/org/drpowell/tabix/TabixIndex.java
//    public static class Chunk implements Comparable<Chunk> {
// 	public final long begin;
// 	public final long end;
// 	public Chunk(final long begin, final long end) {
// 		this.begin = begin; this.end = end;
// 	}
// 	public int compareTo(final Chunk p) {
// 		if (begin == p.begin) {
// 			return cmpUInt64(end, p.end);
// 		} else {
// 			return cmpUInt64(begin, p.begin);
// 		}
// 	}
// 	public static final int cmpUInt64(long u, long v) {
// 		if (u == v) return 0;
// 		return ((u<v) ^ (u<0) ^ (v<0))? -1 : 1;
// 	}
// };


import org.drpowell.tabix.TabixIndex.Chunk;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/* The MIT License

   Copyright (c) 2012 Baylor College of Medicine.

   Permission is hereby granted, free of charge, to any person obtaining
   a copy of this software and associated documentation files (the
   "Software"), to deal in the Software without restriction, including
   without limitation the rights to use, copy, modify, merge, publish,
   distribute, sublicense, and/or sell copies of the Software, and to
   permit persons to whom the Software is furnished to do so, subject to
   the following conditions:

   The above copyright notice and this permission notice shall be
   included in all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
   BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
   ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
   CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
   SOFTWARE.
*/

package org.drpowell.tabix;



/**
 * Maps integers (bin numbers) to a list of chunks that overlap
 * @author bpow
 *
 */
class BinIndex {
	private Map<Integer, List<Chunk>> map;
	public BinIndex(int capacity, float loadFactor) {
		map = new HashMap<Integer, List<Chunk>>(capacity, loadFactor);
	}
	public BinIndex() {
		this(TabixIndex.TBX_MAX_BIN, 1.0f);
	}
	public BinIndex(BinIndex other) {
		// a new clone with size sufficient to hold the contents of "other"
// Path: src/main/java/org/drpowell/tabix/TabixIndex.java
//    public static class Chunk implements Comparable<Chunk> {
// 	public final long begin;
// 	public final long end;
// 	public Chunk(final long begin, final long end) {
// 		this.begin = begin; this.end = end;
// 	}
// 	public int compareTo(final Chunk p) {
// 		if (begin == p.begin) {
// 			return cmpUInt64(end, p.end);
// 		} else {
// 			return cmpUInt64(begin, p.begin);
// 		}
// 	}
// 	public static final int cmpUInt64(long u, long v) {
// 		if (u == v) return 0;
// 		return ((u<v) ^ (u<0) ^ (v<0))? -1 : 1;
// 	}
// };


// Path: src/main/java/org/drpowell/tabix/BinIndex.java
import org.drpowell.tabix.TabixIndex.Chunk;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/* The MIT License

   Copyright (c) 2012 Baylor College of Medicine.

   Permission is hereby granted, free of charge, to any person obtaining
   a copy of this software and associated documentation files (the
   "Software"), to deal in the Software without restriction, including
   without limitation the rights to use, copy, modify, merge, publish,
   distribute, sublicense, and/or sell copies of the Software, and to
   permit persons to whom the Software is furnished to do so, subject to
   the following conditions:

   The above copyright notice and this permission notice shall be
   included in all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
   BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
   ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
   CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
   SOFTWARE.
*/

package org.drpowell.tabix;



/**
 * Maps integers (bin numbers) to a list of chunks that overlap
 * @author bpow
 *
 */
class BinIndex {
	private Map<Integer, List<Chunk>> map;
	public BinIndex(int capacity, float loadFactor) {
		map = new HashMap<Integer, List<Chunk>>(capacity, loadFactor);
	}
	public BinIndex() {
		this(TabixIndex.TBX_MAX_BIN, 1.0f);
	}
	public BinIndex(BinIndex other) {
		// a new clone with size sufficient to hold the contents of "other"
		map = new HashMap<Integer, List<Chunk>>(other.map);