/** * Compare the path of this current entry to another iterator's entry. * * @param p * the other iterator to compare the path against. * @return -1 if this entry sorts first; 0 if the entries are equal; 1 if * p's entry sorts first. */ public int pathCompare(AbstractTreeIterator p) { return pathCompare(p, p.mode); }
/** * Create an iterator for a subtree of an existing iterator. * <p> * The caller is responsible for setting up the path of the child iterator. * * @param p * parent tree iterator. * @param childPath * path array to be used by the child iterator. This path must * contain the path from the top of the walk to the first child * and must end with a '/'. * @param childPathOffset * position within <code>childPath</code> where the child can * insert its data. The value at * <code>childPath[childPathOffset-1]</code> must be '/'. */ public AbstractTreeIterator(AbstractTreeIterator p, byte[] childPath, int childPathOffset) { parent = p; path = childPath; pathOffset = childPathOffset; }
/** * Check if the current entry of both iterators has the same id. * <p> * This method is faster than {@link #getEntryObjectId()} as it does not * require copying the bytes out of the buffers. A direct {@link #idBuffer} * compare operation is performed. * * @param otherIterator * the other iterator to test against. * @return true if both iterators have the same object id; false otherwise. */ public virtual bool idEqual(AbstractTreeIterator otherIterator) { return ObjectId.Equals(idBuffer(), idOffset(), otherIterator.idBuffer(), otherIterator.idOffset()); }
/** * Create a new iterator with no parent and a prefix. * <p> * The prefix path supplied is inserted in front of all paths generated by * this iterator. It is intended to be used when an iterator is being * created for a subsection of an overall repository and needs to be * combined with other iterators that are created to run over the entire * repository namespace. * * @param prefix * position of this iterator in the repository tree. The value * may be null or the empty array to indicate the prefix is the * root of the repository. A trailing slash ('/') is * automatically appended if the prefix does not end in '/'. */ public AbstractTreeIterator(byte[] prefix) { parent = null; if (prefix != null && prefix.Length > 0) { pathLen = prefix.Length; path = new byte[Math.Max(DEFAULT_PATH_SIZE, pathLen + 1)]; Array.Copy(prefix, 0, path, 0, pathLen); if (path[pathLen - 1] != (byte)'/') path[pathLen++] = (byte)'/'; pathOffset = pathLen; } else { path = new byte[DEFAULT_PATH_SIZE]; pathOffset = 0; } }
/** * Create an iterator for a subtree of an existing iterator. * * @param p * parent tree iterator. */ public AbstractTreeIterator(AbstractTreeIterator p) { parent = p; path = p.path; pathOffset = p.pathLen + 1; try { path[pathOffset - 1] = (byte)'/'; } catch (IndexOutOfRangeException e) { growPath(p.pathLen); path[pathOffset - 1] = (byte)'/'; } }
private CanonicalTreeParser(AbstractTreeIterator p) : base(p) { }
/** * Create a new iterator with no parent and a prefix. * <p> * The prefix path supplied is inserted in front of all paths generated by * this iterator. It is intended to be used when an iterator is being * created for a subsection of an overall repository and needs to be * combined with other iterators that are created to run over the entire * repository namespace. * * @param prefix * position of this iterator in the repository tree. The value * may be null or the empty string to indicate the prefix is the * root of the repository. A trailing slash ('/') is * automatically appended if the prefix does not end in '/'. */ public AbstractTreeIterator(string prefix) { parent = null; if (prefix != null && prefix.Length > 0) { byte[] b = Constants.CHARSET.GetBytes(prefix); pathLen = b.Length; path = new byte[Math.Max(DEFAULT_PATH_SIZE, pathLen + 1)]; Array.Copy(b, 0, path, 0, pathLen); if (path[pathLen - 1] != (byte)'/') path[pathLen++] = (byte)'/'; pathOffset = pathLen; } else { path = new byte[DEFAULT_PATH_SIZE]; pathOffset = 0; } }
private static int AlreadyMatch(AbstractTreeIterator a, AbstractTreeIterator b) { while (true) { AbstractTreeIterator ap = a._parent; AbstractTreeIterator bp = b._parent; if (ap == null || bp == null) { return 0; } if (ap.Matches == bp.Matches) { return a.PathOffset; } a = ap; b = bp; } }
/// <summary> /// Create a new iterator with no parent. /// </summary> protected AbstractTreeIterator() { _parent = null; Path = new byte[DEFAULT_PATH_SIZE]; PathOffset = 0; }
/// <summary> /// Compare the path of this current entry to another iterator's entry. /// </summary> /// <param name="treeIterator"> /// The other iterator to compare the path against. /// </param> /// <returns> /// return -1 if this entry sorts first; 0 if the entries are equal; 1 if /// <paramref name="treeIterator"/>'s entry sorts first. /// </returns> public int pathCompare(AbstractTreeIterator treeIterator) { return pathCompare(treeIterator, treeIterator.Mode); }
/// <summary> /// Compare the path of this current entry to another iterator's entry. /// </summary> /// <param name="treeIterator"> /// The other iterator to compare the path against. /// </param> /// <param name="treeIteratorMode"> /// The other iterator <see cref="FileMode"/> bits. /// </param> /// <returns> /// return -1 if this entry sorts first; 0 if the entries are equal; 1 if /// <paramref name="treeIterator"/>'s entry sorts first. /// </returns> public int pathCompare(AbstractTreeIterator treeIterator, int treeIteratorMode) { byte[] a = Path; byte[] b = treeIterator.Path; int aLen = PathLen; int bLen = treeIterator.PathLen; // Its common when we are a subtree for both parents to match; // when this happens everything in _path[0..cPos] is known to // be equal and does not require evaluation again. // int cPos = AlreadyMatch(this, treeIterator); for (; cPos < aLen && cPos < bLen; cPos++) { int cmp = (a[cPos] & 0xff) - (b[cPos] & 0xff); if (cmp != 0) { return cmp; } } if (cPos < aLen) { return (a[cPos] & 0xff) - LastPathChar(treeIteratorMode); } if (cPos < bLen) { return LastPathChar(Mode) - (b[cPos] & 0xff); } return LastPathChar(Mode) - LastPathChar(treeIteratorMode); }
/// <summary> /// Create an iterator for a subtree of an existing iterator. /// The caller is responsible for setting up the path of the child iterator. /// </summary> /// <param name="p">parent tree iterator.</param> /// <param name="childPath"> /// Path array to be used by the child iterator. This path must /// contain the path from the top of the walk to the first child /// and must end with a '/'. /// </param> /// <param name="childPathOffset"> /// position within <code>childPath</code> where the child can /// insert its data. The value at /// <code>childPath[childPathOffset-1]</code> must be '/'. /// </param> protected AbstractTreeIterator(AbstractTreeIterator p, byte[] childPath, int childPathOffset) { _parent = p; Path = childPath; PathOffset = childPathOffset; }
/// <summary> /// Create an iterator for a subtree of an existing iterator. /// </summary> /// <param name="p">parent tree iterator.</param> protected AbstractTreeIterator(AbstractTreeIterator p) { _parent = p; Path = p.Path; PathOffset = p.PathLen + 1; try { Path[PathOffset - 1] = (byte)'/'; } catch (IndexOutOfRangeException) { growPath(p.PathLen); Path[PathOffset - 1] = (byte)'/'; } }
/// <summary> /// Create a new iterator with no parent and a prefix. /// /// The prefix path supplied is inserted in front of all paths generated by /// this iterator. It is intended to be used when an iterator is being /// created for a subsection of an overall repository and needs to be /// combined with other iterators that are created to run over the entire /// repository namespace. /// </summary> /// <param name="prefix"> /// position of this iterator in the repository tree. The value /// may be null or the empty array to indicate the prefix is the /// root of the repository. A trailing slash ('/') is /// automatically appended if the prefix does not end in '/'. /// </param> protected AbstractTreeIterator(byte[] prefix) { _parent = null; if (prefix != null && prefix.Length > 0) { PathLen = prefix.Length; Path = new byte[Math.Max(DEFAULT_PATH_SIZE, PathLen + 1)]; Array.Copy(prefix, 0, Path, 0, PathLen); if (Path[PathLen - 1] != (byte)'/') { Path[PathLen++] = (byte)'/'; } PathOffset = PathLen; } else { Path = new byte[DEFAULT_PATH_SIZE]; PathOffset = 0; } }
public int pathCompare(AbstractTreeIterator p, int pMode) { byte[] a = path; byte[] b = p.path; int aLen = pathLen; int bLen = p.pathLen; int cPos; // Its common when we are a subtree for both parents to match; // when this happens everything in path[0..cPos] is known to // be equal and does not require evaluation again. // cPos = alreadyMatch(this, p); for (; cPos < aLen && cPos < bLen; cPos++) { int cmp = (a[cPos] & 0xff) - (b[cPos] & 0xff); if (cmp != 0) return cmp; } if (cPos < aLen) return (a[cPos] & 0xff) - lastPathChar(pMode); if (cPos < bLen) return lastPathChar(mode) - (b[cPos] & 0xff); return lastPathChar(mode) - lastPathChar(pMode); }
/** Create a new iterator with no parent. */ public AbstractTreeIterator() { parent = null; path = new byte[DEFAULT_PATH_SIZE]; pathOffset = 0; }
private static int alreadyMatch(AbstractTreeIterator a, AbstractTreeIterator b) { for (; ; ) { AbstractTreeIterator ap = a.parent; AbstractTreeIterator bp = b.parent; if (ap == null || bp == null) return 0; if (ap.matches == bp.matches) return a.pathOffset; a = ap; b = bp; } }
private static string NameOf(AbstractTreeIterator i) { return RawParseUtils.decode(Constants.CHARSET, i.Path, 0, i.PathLen); }