Skip to content

Commit

Permalink
libdeng2: Unified terminology of PathTree and Path
Browse files Browse the repository at this point in the history
Paths are composed of segments.
  • Loading branch information
skyjake committed Nov 25, 2012
1 parent 2d9d72a commit 05750e8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 36 deletions.
34 changes: 17 additions & 17 deletions doomsday/libdeng2/include/de/data/pathtree.h
Expand Up @@ -38,21 +38,21 @@ namespace de
* For example, the path <pre>"c:/somewhere/something"</pre> contains three
* path segments: <pre>[ 0: "c:", 1: "somewhere", 2: "something" ]</pre>
*
* @em Delimiter is the term given to the separators between segments.
* (Such as forward slashes in an UNIX-style file path).
* Segments are separated by @em separator @em characters. For instance,
* UNIX file paths use forward slashes as separators.
*
* Internally, segments are "pooled" such that only one instance of a
* segment is included in the model of the whole tree. Potentially, this
* significantly reduces the memory overhead which would otherwise be
* necessary to represent the complete hierarchy as a set of fully composed
* paths.
*
* Delimiters are not included in the hierarchy model. Not including the
* delimiters allows for optimal dynamic replacement when recomposing the
* Separators are not included in the hierarchy model. Not including the
* separators allows for optimal dynamic replacement when recomposing the
* original paths (also reducing the memory overhead for the whole data
* set). One potential use for this feature when representing file path
* hierarchies is "ambidextrously" recomposing paths with either forward or
* backward slashes, irrespective of the delimiter used at path insertion
* backward slashes, irrespective of the separator used at path insertion
* time.
*
* Somewhat similar to a Prefix Tree (Trie) representationally although
Expand Down Expand Up @@ -107,7 +107,7 @@ namespace de
static Path::hash_type const no_hash;

#ifdef DENG2_DEBUG
void debugPrint(QChar delimiter = '/') const;
void debugPrint(QChar separator = '/') const;
void debugPrintHashDistribution() const;
#endif

Expand Down Expand Up @@ -162,13 +162,13 @@ namespace de
* Composes the path for this node. The whole path is upwardly
* reconstructed toward the root of the hierarchy.
*
* @param delimiter Names in the composed path hierarchy will be delimited
* with this character. Paths to branches always include
* a terminating delimiter.
* @param sep Segments in the composed path hierarchy are separatered
* with this character. Paths to branches always include
* a terminating separator.
*
* @return The composed uri.
*/
Path composePath(QChar delimiter = '/') const;
Path composePath(QChar sep = '/') const;

/**
* Sets the user-specified custom pointer.
Expand Down Expand Up @@ -222,7 +222,7 @@ namespace de

/**
* Add a new path into the hierarchy. Duplicates are automatically pruned.
* Delimiters in the path are completely ignored.
* Separators in the path are completely ignored.
*
* @param path New path to be added to the tree. Note that this path is
* NOT resolved before insertion, so any symbolics contained
Expand Down Expand Up @@ -260,15 +260,15 @@ namespace de
/**
* Collate all referenced paths in the hierarchy into a list.
*
* @param found Set of paths that match the result.
* @param flags Comparison behavior flags.
* @param delimiter Names in the composed path hierarchy will be delimited
* with this character. Paths to branches always include
* a terminating delimiter.
* @param found Set of paths that match the result.
* @param flags Comparison behavior flags.
* @param sep Segments in the composed path will be separated
* with this character. Paths to branches always include
* a terminating separator.
*
* @return Number of paths found.
*/
int findAllPaths(FoundPaths &found, ComparisonFlags flags = 0, QChar delimiter = '/') const;
int findAllPaths(FoundPaths &found, ComparisonFlags flags = 0, QChar sep = '/') const;

/**
* Traverse the node hierarchy making a callback for visited node. Traversal
Expand Down
14 changes: 7 additions & 7 deletions doomsday/libdeng2/src/data/pathtree.cpp
Expand Up @@ -286,27 +286,27 @@ PathTree::Nodes const &PathTree::nodes(NodeType type) const
return (type == Leaf? d->leafHash : d->branchHash);
}

static void collectPathsInHash(PathTree::FoundPaths &found, PathTree::Nodes const &ph, QChar delimiter)
static void collectPathsInHash(PathTree::FoundPaths &found, PathTree::Nodes const &ph, QChar separator)
{
if(ph.empty()) return;

DENG2_FOR_EACH_CONST(PathTree::Nodes, i, ph)
{
PathTree::Node const &node = **i;
found.push_back(node.composePath(delimiter));
found.push_back(node.composePath(separator));
}
}

int PathTree::findAllPaths(FoundPaths &found, ComparisonFlags flags, QChar delimiter) const
int PathTree::findAllPaths(FoundPaths &found, ComparisonFlags flags, QChar separator) const
{
int numFoundSoFar = found.count();
if(!(flags & NoBranch))
{
collectPathsInHash(found, branchNodes(), delimiter);
collectPathsInHash(found, branchNodes(), separator);
}
if(!(flags & NoLeaf))
{
collectPathsInHash(found, leafNodes(), delimiter);
collectPathsInHash(found, leafNodes(), separator);
}
return found.count() - numFoundSoFar;
}
Expand Down Expand Up @@ -369,12 +369,12 @@ int PathTree::traverse(ComparisonFlags flags, PathTree::Node *parent, Path::hash
}

#ifdef DENG2_DEBUG
void PathTree::debugPrint(QChar delimiter) const
void PathTree::debugPrint(QChar separator) const
{
LOG_AS("PathTree");
LOG_INFO("[%p]:") << de::dintptr(this);
FoundPaths found;
if(findAllPaths(found, 0, delimiter))
if(findAllPaths(found, 0, separator))
{
qSort(found.begin(), found.end());

Expand Down
24 changes: 12 additions & 12 deletions doomsday/libdeng2/src/data/pathtreenode.cpp
Expand Up @@ -222,14 +222,14 @@ namespace internal {
struct PathConstructorParams {
size_t length;
String composedPath;
QChar delimiter;
QChar separator;
};
}

/**
* Recursive path constructor. First finds the root and the full length of the
* path (when descending), then allocates memory for the string, and finally
* copies each fragment with the delimiters (on the way out).
* copies each segment with the separators (on the way out).
*/
static void pathConstructor(internal::PathConstructorParams &parm, PathTree::Node const &trav)
{
Expand All @@ -243,18 +243,18 @@ static void pathConstructor(internal::PathConstructorParams &parm, PathTree::Nod

if(trav.parent())
{
if(!parm.delimiter.isNull())
if(!parm.separator.isNull())
{
// There also needs to be a delimiter (a single character).
// There also needs to be a separator (a single character).
parm.length += 1;
}

// Descend to parent level.
pathConstructor(parm, *trav.parent());

// Append the separator.
if(!parm.delimiter.isNull())
parm.composedPath.append(parm.delimiter);
if(!parm.separator.isNull())
parm.composedPath.append(parm.separator);
}
// We've arrived at the deepest level. The full length is now known.
// Ensure there's enough memory for the string.
Expand All @@ -281,23 +281,23 @@ static void pathConstructor(internal::PathConstructorParams &parm, PathTree::Nod
*
* Perhaps a fixed size MRU cache? -ds
*/
Path PathTree::Node::composePath(QChar delimiter) const
Path PathTree::Node::composePath(QChar sep) const
{
internal::PathConstructorParams parm = { 0, String(), delimiter };
internal::PathConstructorParams parm = { 0, String(), sep };
#ifdef LIBDENG_STACK_MONITOR
stackStart = &parm;
#endif

// Include a terminating path delimiter for branches.
if(!delimiter.isNull() && !isLeaf())
if(!sep.isNull() && !isLeaf())
parm.length += 1; // A single character.

// Recursively construct the path from fragments and delimiters.
pathConstructor(parm, *this);

// Terminating delimiter for branches.
if(!delimiter.isNull() && !isLeaf())
parm.composedPath += delimiter;
if(!sep.isNull() && !isLeaf())
parm.composedPath += sep;

DENG2_ASSERT(parm.composedPath.length() == (int)parm.length);

Expand All @@ -306,7 +306,7 @@ Path PathTree::Node::composePath(QChar delimiter) const
LOG_INFO("Max stack depth: %1 bytes") << maxStackDepth;
#endif

return Path(parm.composedPath, delimiter);
return Path(parm.composedPath, sep);
}

} // namespace de

0 comments on commit 05750e8

Please sign in to comment.