diff src/org/tmatesoft/hg/internal/IntMap.java @ 281:81e9a3c9bafe

Utilize IntMap when caching manifest revisions
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 02 Sep 2011 13:59:21 +0200
parents 55fad5e0e98b
children ee8264d80747 2e402c12ebc6
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/internal/IntMap.java	Fri Sep 02 13:40:09 2011 +0200
+++ b/src/org/tmatesoft/hg/internal/IntMap.java	Fri Sep 02 13:59:21 2011 +0200
@@ -109,6 +109,39 @@
 		}
 		return null;
 	}
+	
+	public void remove(int key) {
+		int ix = binarySearch(keys, size, key);
+		if (ix >= 0) {
+			if (ix <= size - 1) {
+				System.arraycopy(keys, ix+1, keys, ix, size - ix - 1);
+				System.arraycopy(values, ix+1, values, ix, size - ix - 1);
+			} // if ix points to last element, no reason to attempt a copy
+			size--;
+			keys[size] = 0;
+			values[size] = null;
+		}
+	}
+	
+	/**
+	 * Forget first N entries (in natural order) in the map.
+	 */
+	@Experimental
+	public void removeFromStart(int count) {
+		if (count > 0 && count <= size) {
+			if (count < size) {
+				System.arraycopy(keys, count, keys, 0, size - count);
+				System.arraycopy(values, count, values, 0, size - count);
+			}
+			for (int i = size - count; i < size; i++) {
+				keys[i] = 0;
+				values[i] = null;
+			}
+			size -= count;
+		} 
+	}
+	
+	
 
 	// copy of Arrays.binarySearch, with upper search limit as argument
 	private static int binarySearch(int[] a, int high, int key) {