1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
Name compression:
{prefix}/{suffix} -> {prefix} if {prefix} is unique
{prefix}/{suffix} -> {suffix} if {suffix} is unique
{prefix}/{middle}/{suffix} -> {prefix}/{suffix} if unique
Consider array subscripts independently from name portions.
Apply name compression only to the most-preferred name for each node.
Algorithm (greedy):
Input is a name of the form:
Name *
shorten(startName)
Name *startName; /* nk/.../n1/n0 */
{
Name *best, *prefix, *suffix;
int bestLength, length, i;
best = startName;
bestLength = nameLength(startName);
/* Find small suffixes */
for (suffix = NULL, i = 0; i <= bestLength + 1; i++)
{
newName = "ni/.../n0";
if (totallyUnique(newName) && suffixUnique(newName))
{
suffix = newName;
break;
}
}
if (suffix && nameLength(suffix) < bestLength)
{
best = suffix;
bestLength = nameLength(suffix);
}
/* Find small prefixes */
for (prefix = NULL, i = bestLength + 1; i >= 0; i--)
{
newName = "nk/.../ni";
if (totallyUnique(newName) && prefixUnique(newName))
{
prefix = newName;
break;
}
}
if (prefix && nameLength(prefix) < bestLength)
{
best = prefix;
bestLength = nameLength(prefix);
}
/*
* Consider eliding inner parts of the name.
* This loop starts with the smallest length and goes up
* to names of length bestLength.
*/
for (length = 1; length < bestLength; length++)
if (genAllSubNames(startName, length, elideFunc, &best))
break;
return best;
}
/*
* totallyUnique --
*
* Determine whether 'name' is unique with respect to all the
* names currently in nameTable.
*
* Results:
* TRUE if 'name' is unique, FALSE if not.
*
* Side effects:
* None.
*/
bool
totallyUnique(name)
Name *name;
{
}
/*
* prefixUnique --
*
* Compare 'name' with all other names in nameTable, looking
* only at the leading components of these names. If 'name'
* isn't unique with respect to the set of names formed by
* the leading components, return FALSE.
*
* Results:
* TRUE if 'name' is unique as described above, FALSE if not.
*
* Side effects:
* None.
*/
bool
prefixUnique(name)
Name *name;
{
}
/*
* suffixUnique --
*
* Compare 'name' with all other names in nameTable, looking
* only at the trailing components of these names. If 'name'
* isn't unique with respect to the set of names formed by
* the trailing components, return FALSE.
*
* Results:
* TRUE if 'name' is unique as described above, FALSE if not.
*
* Side effects:
* None.
*/
bool
suffixUnique(name)
Name *name;
{
}
/*
* genAllSubNames --
*
* Generate all subnames of 'name' that are of length 'subLength'.
* Call (*func)() on each name, where (*func)() is of the following
* form:
*
* int
* (*func)(name, cdata)
* Name *name;
* ClientData cdata;
* {
* }
*
* This function should return 0 if genAllSubNames() should continue
* generating names, or 1 if we should stop.
*
* Results:
* Returns 1 if (*func)() aborted the generation; otherwise
* returns 0.
*
* Side effects:
* None other than those caused by (*func)().
*/
int
genAllSubNames(name, subLength, func, cdata)
Name *name;
int subLength;
int (*func)();
ClientData cdata;
{
}
|