MCPcopy Create free account
hub / github.com/Snapchat/Valdi / hash

Method hash

valdi_core/src/valdi_core/cpp/Utils/Value.cpp:819–866  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

817}
818
819size_t Value::hash() const {
820 switch (_type) {
821 case ValueType::Null:
822 case ValueType::Undefined:
823 return 0;
824 case ValueType::InternedString:
825 return toStringBox().hash();
826 case ValueType::StaticString:
827 return getStaticString()->hash();
828 case ValueType::Int:
829 return static_cast<size_t>(toInt());
830 case ValueType::Long:
831 return static_cast<size_t>(toLong());
832 case ValueType::Double:
833 return static_cast<size_t>(toDouble());
834 case ValueType::Bool:
835 return static_cast<size_t>(toBool());
836 case ValueType::Map: {
837 std::size_t hash = 0;
838
839 for (const auto& it : *getMap()) {
840 boost::hash_combine(hash, it.first.hash());
841 boost::hash_combine(hash, it.second.hash());
842 }
843 return hash;
844 }
845 case ValueType::Array: {
846 std::size_t hash = 0;
847
848 for (const auto& it : *getArray()) {
849 boost::hash_combine(hash, it.hash());
850 }
851 return hash;
852 }
853 case ValueType::TypedArray:
854 return getTypedArray()->getBuffer().hash();
855 case ValueType::Function:
856 return reinterpret_cast<size_t>(getFunction());
857 case ValueType::Error:
858 return getError().hash();
859 case ValueType::TypedObject:
860 return getTypedObject()->hash();
861 case ValueType::ProxyTypedObject:
862 return reinterpret_cast<size_t>(getProxyObject());
863 case ValueType::ValdiObject:
864 return reinterpret_cast<size_t>(getValdiObject().get());
865 }
866}
867
868Error Value::invalidTypeError(ValueType expectedType, ValueType actualType) {
869 return Error(STRING_FORMAT(

Callers 1

operator()Method · 0.45

Calls 4

toStringBoxFunction · 0.85
hash_combineFunction · 0.85
getErrorFunction · 0.85
getMethod · 0.65

Tested by

no test coverage detected