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