Mercurial > hg4j
comparison src/org/tmatesoft/hg/repo/Revlog.java @ 368:8107b95f4280
Update Javadoc with 'revision index'
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 16 Dec 2011 16:00:57 +0100 |
parents | 2fadf8695f8a |
children | 6150555eb41d |
comparison
equal
deleted
inserted
replaced
367:2fadf8695f8a | 368:8107b95f4280 |
---|---|
124 } | 124 } |
125 }); | 125 }); |
126 } | 126 } |
127 | 127 |
128 /** | 128 /** |
129 * Get local revision number (index) of the specified revision. | 129 * Get local index of the specified revision. |
130 * If unsure, use {@link #isKnown(Nodeid)} to find out whether nodeid belongs to this revlog. | 130 * If unsure, use {@link #isKnown(Nodeid)} to find out whether nodeid belongs to this revlog. |
131 * | 131 * |
132 * For occasional queries, this method works with decent performance, despite its O(n/2) approach. | 132 * For occasional queries, this method works with decent performance, despite its O(n/2) approach. |
133 * Alternatively, if you need to perform multiple queries (e.g. at least 15-20), {@link RevisionMap} may come handy. | 133 * Alternatively, if you need to perform multiple queries (e.g. at least 15-20), {@link RevisionMap} may come handy. |
134 * | 134 * |
180 protected void rawContent(Nodeid nodeid, ByteChannel sink) throws HgException, IOException, CancelledException, HgInvalidRevisionException { | 180 protected void rawContent(Nodeid nodeid, ByteChannel sink) throws HgException, IOException, CancelledException, HgInvalidRevisionException { |
181 rawContent(getRevisionIndex(nodeid), sink); | 181 rawContent(getRevisionIndex(nodeid), sink); |
182 } | 182 } |
183 | 183 |
184 /** | 184 /** |
185 * @param revision - repo-local index of this file change (not a changelog revision number!) | 185 * @param fileRevisionIndex - index of this file change (not a changelog revision index), non-negative. From predefined constants, only {@link HgRepository#TIP} makes sense. |
186 * FIXME is it necessary to have IOException along with HgException here? | 186 * FIXME is it necessary to have IOException along with HgException here? |
187 */ | 187 */ |
188 protected void rawContent(int revision, ByteChannel sink) throws HgException, IOException, CancelledException, HgInvalidRevisionException { | 188 protected void rawContent(int fileRevisionIndex, ByteChannel sink) throws HgException, IOException, CancelledException, HgInvalidRevisionException { |
189 if (sink == null) { | 189 if (sink == null) { |
190 throw new IllegalArgumentException(); | 190 throw new IllegalArgumentException(); |
191 } | 191 } |
192 ContentPipe insp = new ContentPipe(sink, 0, repo.getContext().getLog()); | 192 ContentPipe insp = new ContentPipe(sink, 0, repo.getContext().getLog()); |
193 insp.checkCancelled(); | 193 insp.checkCancelled(); |
194 content.iterate(revision, revision, true, insp); | 194 content.iterate(fileRevisionIndex, fileRevisionIndex, true, insp); |
195 insp.checkFailed(); | 195 insp.checkFailed(); |
196 } | 196 } |
197 | 197 |
198 /** | 198 /** |
199 * XXX perhaps, return value Nodeid[2] and boolean needNodeids is better (and higher level) API for this query? | 199 * XXX perhaps, return value Nodeid[2] and boolean needNodeids is better (and higher level) API for this query? |
290 public interface Inspector { | 290 public interface Inspector { |
291 } | 291 } |
292 | 292 |
293 @Experimental | 293 @Experimental |
294 public interface RevisionInspector extends Inspector { | 294 public interface RevisionInspector extends Inspector { |
295 void next(int revisionIndex, Nodeid revision, int linkedRevision); | 295 void next(int revisionIndex, Nodeid revision, int linkedRevisionIndex); |
296 } | 296 } |
297 | 297 |
298 @Experimental | 298 @Experimental |
299 public interface ParentInspector extends Inspector { | 299 public interface ParentInspector extends Inspector { |
300 // XXX document whether parentX is -1 or a constant (BAD_REVISION? or dedicated?) | 300 // XXX document whether parentX is -1 or a constant (BAD_REVISION? or dedicated?) |
493 | 493 |
494 /** | 494 /** |
495 * Effective int to Nodeid and vice versa translation. It's advised to use this class instead of | 495 * Effective int to Nodeid and vice versa translation. It's advised to use this class instead of |
496 * multiple {@link Revlog#getRevisionIndex(Nodeid)} calls. | 496 * multiple {@link Revlog#getRevisionIndex(Nodeid)} calls. |
497 * | 497 * |
498 * getRevisionIndex(Nodeid) with straightforward lookup approach performs O(n/2) | 498 * {@link Revlog#getRevisionIndex(Nodeid)} with straightforward lookup approach performs O(n/2) |
499 * #localRevision() is log(n), plus initialization is O(n) | 499 * {@link RevisionMap#revisionIndex(Nodeid)} is log(n), plus initialization is O(n) (just once). |
500 */ | 500 */ |
501 public final class RevisionMap implements RevisionInspector { | 501 public final class RevisionMap implements RevisionInspector { |
502 /* | 502 /* |
503 * in fact, initialization is much slower as it instantiates Nodeids, while #getLocalRevision | 503 * in fact, initialization is much slower as it instantiates Nodeids, while #getRevisionIndex |
504 * compares directly against byte buffer. Measuring cpython with 70k+ gives 3 times difference (47 vs 171) | 504 * compares directly against byte buffer. Measuring cpython with 70k+ gives 3 times difference (47 vs 171) |
505 * for complete changelog iteration. | 505 * for complete changelog iteration. |
506 */ | 506 */ |
507 | 507 |
508 /* | 508 /* |