Пример #1
0
 /** \brief create object with rage-check.
  *  \param v value to represent.
  */
 Similarity(const double v):
   sum_(v),
   count_(1)
 {
   if( !std::isfinite(v) )
     throw ExceptionInvalidValue(SYSTEM_SAVE_LOCATION, "value is not finite (inf/nan)", v);
   if(v<0)
     throw ExceptionInvalidValue(SYSTEM_SAVE_LOCATION, "value too small", v);
   if(1<v)
     throw ExceptionInvalidValue(SYSTEM_SAVE_LOCATION, "value too big", v);
 }
Пример #2
0
    ObjectID::ObjectID(const std::string& objectid)
    {
        std::string objectidcopy;

        for (auto& itr : objectid)
        {
            if (isalnum(itr))
            {
                objectidcopy.push_back(tolower(itr));
                continue;
            }

            switch (itr)
            {
                case ID_CHAR_PLUS:
                case ID_CHAR_MINUS:
                case ID_CHAR_SEPARATOR:
                case ID_CHAR_UNDERSCOPE:
                    objectidcopy.push_back(itr);
                    break;

                default:
                    break;
            }
        }

        replaceRepetitions(objectidcopy, ID_CHAR_UNDERSCOPE);
        replaceRepetitions(objectidcopy, ID_CHAR_MINUS);
        replaceRepetitions(objectidcopy, ID_CHAR_PLUS);
        replaceRepetitions(objectidcopy, ID_CHAR_SEPARATOR);

        if (objectidcopy.length() == 0)
        {
            throw ExceptionInvalidValue(SGE_DEBUG_TRACE());
        }

        hash_id = Fnv64_t(14695981039346656037UL);

        for (auto& itr : objectidcopy)
        {
            if (itr == ID_CHAR_SEPARATOR)
            {
                continue;
            }

            hash_id ^= Fnv64_t(itr);
            hash_id += ((hash_id << 1) + (hash_id << 4) + (hash_id << 5) +
                        (hash_id << 7) + (hash_id << 8) + (hash_id << 40));
        }
    }