comparison src/org/tmatesoft/hg/internal/IntVector.java @ 680:58a6900f845d

Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Sun, 21 Jul 2013 17:15:34 +0200
parents f41dd9a3b8af
children
comparison
equal deleted inserted replaced
679:19f5167c2155 680:58a6900f845d
22 * Vector of primitive values 22 * Vector of primitive values
23 * 23 *
24 * @author Artem Tikhomirov 24 * @author Artem Tikhomirov
25 * @author TMate Software Ltd. 25 * @author TMate Software Ltd.
26 */ 26 */
27 public class IntVector { 27 public class IntVector implements Cloneable {
28 28
29 private int[] data; 29 private int[] data;
30 private final int increment; 30 private final int increment;
31 private int count; 31 private int count;
32 32
55 } 55 }
56 for (int v : values) { 56 for (int v : values) {
57 data[count++] = v; 57 data[count++] = v;
58 } 58 }
59 } 59 }
60 60
61 public void addAll(IntVector other) {
62 final int otherLen = other.count;
63 if (count + otherLen > data.length) {
64 grow(count + otherLen);
65 }
66 for (int i = 0; i < otherLen; i++) {
67 data[count++] = other.data[i];
68 }
69 }
70
61 public int get(int i) { 71 public int get(int i) {
62 if (i < 0 || i >= count) { 72 if (i < 0 || i >= count) {
63 throw new IndexOutOfBoundsException(String.format("Index: %d, size: %d", i, count)); 73 throw new IndexOutOfBoundsException(String.format("Index: %d, size: %d", i, count));
64 } 74 }
65 return data[i]; 75 return data[i];
124 134
125 @Override 135 @Override
126 public String toString() { 136 public String toString() {
127 return String.format("%s[%d]", IntVector.class.getSimpleName(), size()); 137 return String.format("%s[%d]", IntVector.class.getSimpleName(), size());
128 } 138 }
139
140 @Override
141 public IntVector clone() {
142 try {
143 return (IntVector) super.clone();
144 } catch (CloneNotSupportedException ex) {
145 throw new Error(ex);
146 }
147 }
129 148
130 /** 149 /**
131 * Use only when this instance won't be used any longer 150 * Use only when this instance won't be used any longer
132 */ 151 */
133 int[] toArray(boolean internalIfSizeMatchCapacity) { 152 int[] toArray(boolean internalIfSizeMatchCapacity) {