Mercurial > jhg
comparison 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 |
comparison
equal
deleted
inserted
replaced
280:35125450c804 | 281:81e9a3c9bafe |
---|---|
107 if (ix >= 0) { | 107 if (ix >= 0) { |
108 return (V) values[ix]; | 108 return (V) values[ix]; |
109 } | 109 } |
110 return null; | 110 return null; |
111 } | 111 } |
112 | |
113 public void remove(int key) { | |
114 int ix = binarySearch(keys, size, key); | |
115 if (ix >= 0) { | |
116 if (ix <= size - 1) { | |
117 System.arraycopy(keys, ix+1, keys, ix, size - ix - 1); | |
118 System.arraycopy(values, ix+1, values, ix, size - ix - 1); | |
119 } // if ix points to last element, no reason to attempt a copy | |
120 size--; | |
121 keys[size] = 0; | |
122 values[size] = null; | |
123 } | |
124 } | |
125 | |
126 /** | |
127 * Forget first N entries (in natural order) in the map. | |
128 */ | |
129 @Experimental | |
130 public void removeFromStart(int count) { | |
131 if (count > 0 && count <= size) { | |
132 if (count < size) { | |
133 System.arraycopy(keys, count, keys, 0, size - count); | |
134 System.arraycopy(values, count, values, 0, size - count); | |
135 } | |
136 for (int i = size - count; i < size; i++) { | |
137 keys[i] = 0; | |
138 values[i] = null; | |
139 } | |
140 size -= count; | |
141 } | |
142 } | |
143 | |
144 | |
112 | 145 |
113 // copy of Arrays.binarySearch, with upper search limit as argument | 146 // copy of Arrays.binarySearch, with upper search limit as argument |
114 private static int binarySearch(int[] a, int high, int key) { | 147 private static int binarySearch(int[] a, int high, int key) { |
115 int low = 0; | 148 int low = 0; |
116 high--; | 149 high--; |