Mercurial > hg4j
comparison src/org/tmatesoft/hg/internal/IntMap.java @ 415:ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 22 Mar 2012 18:54:11 +0100 |
parents | 81e9a3c9bafe |
children | ccd7d25e5aea |
comparison
equal
deleted
inserted
replaced
414:bb278ccf9866 | 415:ee8264d80747 |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2011 TMate Software Ltd | 2 * Copyright (c) 2011-2012 TMate Software Ltd |
3 * | 3 * |
4 * This program is free software; you can redistribute it and/or modify | 4 * This program is free software; you can redistribute it and/or modify |
5 * it under the terms of the GNU General Public License as published by | 5 * it under the terms of the GNU General Public License as published by |
6 * the Free Software Foundation; version 2 of the License. | 6 * the Free Software Foundation; version 2 of the License. |
7 * | 7 * |
14 * the terms of a license other than GNU General Public License | 14 * the terms of a license other than GNU General Public License |
15 * contact TMate Software at support@hg4j.com | 15 * contact TMate Software at support@hg4j.com |
16 */ | 16 */ |
17 package org.tmatesoft.hg.internal; | 17 package org.tmatesoft.hg.internal; |
18 | 18 |
19 import java.util.Iterator; | |
20 import java.util.Map; | |
21 import java.util.Map.Entry; | |
19 import java.util.NoSuchElementException; | 22 import java.util.NoSuchElementException; |
23 | |
24 import org.tmatesoft.hg.core.Nodeid; | |
20 | 25 |
21 | 26 |
22 /** | 27 /** |
23 * Map implementation that uses plain int keys and performs with log n effectiveness. | 28 * Map implementation that uses plain int keys and performs with log n effectiveness. |
24 * | 29 * |
138 values[i] = null; | 143 values[i] = null; |
139 } | 144 } |
140 size -= count; | 145 size -= count; |
141 } | 146 } |
142 } | 147 } |
143 | 148 |
144 | 149 // document iterator is non-modifying (neither remove() nor setValue() works) |
150 // perhaps, may also implement Iterable<Map.Entry> to use nice for() | |
151 public Iterator<Map.Entry<Integer, V>> entryIterator() { | |
152 class E implements Map.Entry<Integer, V> { | |
153 private Integer key; | |
154 private V value; | |
155 | |
156 public Integer getKey() { | |
157 return key; | |
158 } | |
159 | |
160 public V getValue() { | |
161 return value; | |
162 } | |
163 | |
164 public V setValue(V value) { | |
165 throw new UnsupportedOperationException(); | |
166 } | |
167 | |
168 void init(Integer k, V v) { | |
169 key = k; | |
170 value = v; | |
171 } | |
172 } | |
173 | |
174 return new Iterator<Map.Entry<Integer, V>>() { | |
175 private int i = 0; | |
176 private final E entry = new E(); | |
177 private final int _size; | |
178 private final int[] _keys; | |
179 private final Object[] _values; | |
180 | |
181 { | |
182 _size = IntMap.this.size; | |
183 _keys = IntMap.this.keys; | |
184 _values = IntMap.this.values; | |
185 } | |
186 | |
187 public boolean hasNext() { | |
188 return i < _size; | |
189 } | |
190 | |
191 public Entry<Integer, V> next() { | |
192 if (i >= _size) { | |
193 throw new NoSuchElementException(); | |
194 } | |
195 @SuppressWarnings("unchecked") | |
196 V val = (V) _values[i]; | |
197 entry.init(_keys[i], val); | |
198 i++; | |
199 return entry; | |
200 } | |
201 | |
202 public void remove() { | |
203 throw new UnsupportedOperationException(); | |
204 } | |
205 }; | |
206 } | |
207 | |
208 public Map<Integer, ? super V> fill(Map<Integer, ? super V> map) { | |
209 for (Iterator<Map.Entry<Integer, V>> it = entryIterator(); it.hasNext(); ) { | |
210 Map.Entry<Integer, V> next = it.next(); | |
211 map.put(next.getKey(), next.getValue()); | |
212 } | |
213 return map; | |
214 } | |
145 | 215 |
146 // copy of Arrays.binarySearch, with upper search limit as argument | 216 // copy of Arrays.binarySearch, with upper search limit as argument |
147 private static int binarySearch(int[] a, int high, int key) { | 217 private static int binarySearch(int[] a, int high, int key) { |
148 int low = 0; | 218 int low = 0; |
149 high--; | 219 high--; |