MCPcopy Create free account
hub / github.com/catboost/catboost / TryFloatFromStringFast

Function TryFloatFromStringFast

catboost/libs/data/loader.cpp:412–443  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

410 };
411
412 bool TryFloatFromStringFast(TStringBuf token, float& value) {
413 if (token.empty()) {
414 return false;
415 }
416 static const NFH::TFlatHashMap<TStringBuf, float, TStupidStringHash> wellKnown = {
417 { TStringBuf("0.0"), 0.0f},
418 { TStringBuf("1.0"), 1.0f},
419 { TStringBuf("2.0"), 2.0f},
420 { TStringBuf("3.0"), 3.0f},
421 { TStringBuf("4.0"), 4.0f},
422 { TStringBuf("5.0"), 5.0f},
423 { TStringBuf("6.0"), 6.0f},
424 { TStringBuf("7.0"), 7.0f},
425 { TStringBuf("8.0"), 8.0f},
426 { TStringBuf("9.0"), 9.0f}
427 };
428 if (token.size() == 1 && token[0] >= '0' && token[0] <= '9') {
429 value = float(token[0] - '0');
430 return true;
431 } else if (token.size() == 3) {
432 if ( auto i = wellKnown.find(token); i != wellKnown.end()) {
433 value = i->second;
434 return true;
435 }
436 } else if (token[0] == '-' && token.size() == 4) {
437 if ( auto i = wellKnown.find(token.substr(1)); i != wellKnown.end()) {
438 value = -i->second;
439 return true;
440 }
441 }
442 return TryFromString<float>(token, value);
443 }
444 }
445
446 bool TryFloatFromString(TStringBuf token, bool parseNonFinite, float* value) {

Callers 1

TryFloatFromStringFunction · 0.85

Calls 5

emptyMethod · 0.45
sizeMethod · 0.45
findMethod · 0.45
endMethod · 0.45
substrMethod · 0.45

Tested by

no test coverage detected