static private ConvertToHCIDMetrics ( int keys, |
||
keys | int | |
h | ||
return | string |
internal static string ConvertToHCIDMetrics(int[] keys, IntHashtable h)
{
if (keys.Length == 0)
return null;
int lastCid = 0;
int lastValue = 0;
int start;
for (start = 0; start < keys.Length; ++start) {
lastCid = keys[start];
lastValue = h[lastCid];
if (lastValue != 0) {
++start;
break;
}
}
if (lastValue == 0)
return null;
StringBuilder buf = new StringBuilder();
buf.Append('[');
buf.Append(lastCid);
int state = FIRST;
for (int k = start; k < keys.Length; ++k) {
int cid = keys[k];
int value = h[cid];
if (value == 0)
continue;
switch (state) {
case FIRST: {
if (cid == lastCid + 1 && value == lastValue) {
state = SERIAL;
}
else if (cid == lastCid + 1) {
state = BRACKET;
buf.Append('[').Append(lastValue);
}
else {
buf.Append('[').Append(lastValue).Append(']').Append(cid);
}
break;
}
case BRACKET: {
if (cid == lastCid + 1 && value == lastValue) {
state = SERIAL;
buf.Append(']').Append(lastCid);
}
else if (cid == lastCid + 1) {
buf.Append(' ').Append(lastValue);
}
else {
state = FIRST;
buf.Append(' ').Append(lastValue).Append(']').Append(cid);
}
break;
}
case SERIAL: {
if (cid != lastCid + 1 || value != lastValue) {
buf.Append(' ').Append(lastCid).Append(' ').Append(lastValue).Append(' ').Append(cid);
state = FIRST;
}
break;
}
}
lastValue = value;
lastCid = cid;
}
switch (state) {
case FIRST: {
buf.Append('[').Append(lastValue).Append("]]");
break;
}
case BRACKET: {
buf.Append(' ').Append(lastValue).Append("]]");
break;
}
case SERIAL: {
buf.Append(' ').Append(lastCid).Append(' ').Append(lastValue).Append(']');
break;
}
}
return buf.ToString();
}