MCPcopy Create free account
hub / github.com/apache/impala / FindShortestSeparator

Function FindShortestSeparator

be/src/gutil/strings/util.cc:1135–1173  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1133}
1134
1135void FindShortestSeparator(const StringPiece& start,
1136 const StringPiece& limit,
1137 string* separator) {
1138 // Find length of common prefix
1139 size_t min_length = min(start.size(), limit.size());
1140 size_t diff_index = 0;
1141 while ((diff_index < min_length) &&
1142 (start[diff_index] == limit[diff_index])) {
1143 diff_index++;
1144 }
1145
1146 if (diff_index >= min_length) {
1147 // Handle the case where either string is a prefix of the other
1148 // string, or both strings are identical.
1149 start.CopyToString(separator);
1150 return;
1151 }
1152
1153 if (diff_index+1 == start.size()) {
1154 // If the first difference is in the last character, do not bother
1155 // incrementing that character since the separator will be no
1156 // shorter than "start".
1157 start.CopyToString(separator);
1158 return;
1159 }
1160
1161 if (start[diff_index] == 0xff) {
1162 // Avoid overflow when incrementing start[diff_index]
1163 start.CopyToString(separator);
1164 return;
1165 }
1166
1167 separator->assign(start.data(), diff_index);
1168 separator->push_back(start[diff_index] + 1);
1169 if (*separator >= limit) {
1170 // Never pick a separator that causes confusion with "limit"
1171 start.CopyToString(separator);
1172 }
1173}
1174
1175int SafeSnprintf(char *str, size_t size, const char *format, ...) {
1176 va_list printargs;

Callers

nothing calls this directly

Calls 5

minFunction · 0.85
CopyToStringMethod · 0.80
push_backMethod · 0.80
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected