本文整理汇总了C++中KeyType类的典型用法代码示例。如果您正苦于以下问题:C++ KeyType类的具体用法?C++ KeyType怎么用?C++ KeyType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了KeyType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: searchForAssignment
/// searchForAssignment - Look for a cached solution for a query.
///
/// \param key - The query to look up.
/// \param result [out] - The cached result, if the lookup is succesful. This is
/// either a satisfying assignment (for a satisfiable query), or 0 (for an
/// unsatisfiable query).
/// \return - True if a cached result was found.
bool CexCachingSolver::searchForAssignment(KeyType &key, Assignment *&result) {
Assignment * const *lookup = cache.lookup(key);
if (lookup) {
result = *lookup;
return true;
}
if (CexCacheTryAll) {
// Look for a satisfying assignment for a superset, which is trivially an
// assignment for any subset.
Assignment **lookup = cache.findSuperset(key, NonNullAssignment());
// Otherwise, look for a subset which is unsatisfiable, see below.
if (!lookup)
lookup = cache.findSubset(key, NullAssignment());
// If either lookup succeeded, then we have a cached solution.
if (lookup) {
result = *lookup;
return true;
}
// Otherwise, iterate through the set of current assignments to see if one
// of them satisfies the query.
for (assignmentsTable_ty::iterator it = assignmentsTable.begin(),
ie = assignmentsTable.end(); it != ie; ++it) {
Assignment *a = *it;
if (a->satisfies(key.begin(), key.end())) {
result = a;
return true;
}
}
} else {
// FIXME: Which order? one is sure to be better.
// Look for a satisfying assignment for a superset, which is trivially an
// assignment for any subset.
Assignment **lookup = cache.findSuperset(key, NonNullAssignment());
// Otherwise, look for a subset which is unsatisfiable -- if the subset is
// unsatisfiable then no additional constraints can produce a valid
// assignment. While searching subsets, we also explicitly the solutions for
// satisfiable subsets to see if they solve the current query and return
// them if so. This is cheap and frequently succeeds.
if (!lookup)
lookup = cache.findSubset(key, NullOrSatisfyingAssignment(key));
// If either lookup succeeded, then we have a cached solution.
if (lookup) {
result = *lookup;
return true;
}
}
return false;
}
示例2: getKey
Int32Vector Adfgvx::getPermutationKey() const
{
KeyType key = getKey();
KeyType sorted_key(key);
sorted_key.sort();
Int32Vector perm_key;
perm_key.reserve(key.length());
for (const auto c : key)
{
perm_key.push_back(sorted_key.find(c));
}
return perm_key;
}
示例3: KeyType
/// lookupAssignment - Lookup a cached result for the given \arg query.
///
/// \param query - The query to lookup.
/// \param key [out] - On return, the key constructed for the query.
/// \param result [out] - The cached result, if the lookup is succesful. This is
/// either a satisfying assignment (for a satisfiable query), or 0 (for an
/// unsatisfiable query).
/// \return True if a cached result was found.
bool CexCachingSolver::lookupAssignment(const Query &query,
KeyType &key,
Assignment *&result) {
key = KeyType(query.constraints.begin(), query.constraints.end());
ref<Expr> neg = Expr::createIsZero(query.expr);
bool keyHasAddedConstraint = false;
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(neg)) {
if (CE->isFalse()) {
result = (Assignment*) 0;
++stats::queryCexCacheHits;
return true;
}
} else {
key.insert(neg);
keyHasAddedConstraint = true;
}
bool found = searchForAssignment(key, result);
if (found)
++stats::queryCexCacheHits;
else ++stats::queryCexCacheMisses;
if (keyHasAddedConstraint && !unsatCore.empty()) {
/// Here we remove the added component (neg)
/// from the unsatisfiability core.
unsatCore.erase(std::remove(unsatCore.begin(), unsatCore.end(), neg),
unsatCore.end());
}
return found;
}
示例4: getAssignment
bool CexCachingSolver::getAssignment(const Query& query, Assignment *&result) {
KeyType key;
if (lookupAssignment(query, key, result))
return true;
std::vector<const Array*> objects;
findSymbolicObjects(key.begin(), key.end(), objects);
std::vector< std::vector<unsigned char> > values;
bool hasSolution;
if (!solver->impl->computeInitialValues(query, objects, values,
hasSolution))
return false;
AssignmentCacheWrapper *bindingWrapper;
Assignment *binding;
if (hasSolution) {
binding = new Assignment(objects, values);
// Memoize the result.
std::pair<assignmentsTable_ty::iterator, bool>
res = assignmentsTable.insert(binding);
if (!res.second) {
delete binding;
binding = *res.first;
}
if (DebugCexCacheCheckBinding)
if (!binding->satisfies(key.begin(), key.end())) {
query.dump();
binding->dump();
klee_error("Generated assignment doesn't match query");
}
bindingWrapper = new AssignmentCacheWrapper(binding);
} else {
unsatCore = solver->impl->getUnsatCore();
binding = (Assignment *) 0;
bindingWrapper = new AssignmentCacheWrapper(unsatCore);
}
result = binding;
cache.insert(key, bindingWrapper);
return true;
}
示例5: SetValue
bool ObjectWrapper::SetValue(const KeyType key, JSValueRef value)
{
JSStringRef strKey = JSStringCreateWithUTF8CString(key.c_str());
JSObjectSetProperty(g_ctx, m_obj, strKey, value, kJSPropertyAttributeNone, NULL);
JSStringRelease(strKey);
return true;
}
示例6: GetValue
JSValueRef ObjectWrapper::GetValue(const KeyType key)
{
JSStringRef strKey = JSStringCreateWithUTF8CString(key.c_str());
JSValueRef value = JSObjectGetProperty(g_ctx, m_obj, strKey, NULL);
JSStringRelease(strKey);
return value;
}
示例7: Remove
bool ObjectWrapper::Remove(const KeyType& key)
{
JSStringRef strKey = JSStringCreateWithUTF8CString(key.c_str());
JSObjectDeleteProperty(g_ctx, m_obj, strKey, NULL);
JSStringRelease(strKey);
return true;
}
示例8: HasKey
bool ObjectWrapper::HasKey(const KeyType& key)
{
JSStringRef strKey = JSStringCreateWithUTF8CString(key.c_str());
bool hasProperty = JSObjectHasProperty(g_ctx, m_obj, strKey);
JSStringRelease(strKey);
return hasProperty;
}
示例9: isUniqueWithoutMissingIntegers
bool StringCipherWithPermutationKey::isUniqueWithoutMissingIntegers(const KeyType &key)
{
const uint32_t key_len = key.size();
const std::set<int32_t> sorted_key(key.begin(), key.end());
if (key_len != sorted_key.size())
{
return false;
}
// Check if all integers are between 0 and the size of the key.
const uint32_t max_int = *std::max_element(sorted_key.begin(), sorted_key.end());
if (max_int >= key_len)
{
return false;
}
return true;
}
示例10: freeKey
void KeyHandler::freeKey(KeyType keyId, int playerId)
{
// assert - the right key with player
assert(keyId.getOwnerId() == playerId);
#ifdef _DEBUG
// DEBUG - assert - the key already exists
assert(mFreeKeysChecker[playerId].find(keyId) == mFreeKeysChecker[playerId].end());
// DEBUG - add key to the map
mFreeKeysChecker[playerId][keyId] = true;
#endif
// add the key to the stack
mFreeKeys[playerId].push(keyId);
}
示例11: getAssignment
bool CexCachingSolver::getAssignment(const Query& query, Assignment *&result) {
KeyType key;
if (lookupAssignment(query, key, result))
return true;
std::vector<const Array*> objects;
findSymbolicObjects(key.begin(), key.end(), objects);
std::vector< std::vector<unsigned char> > values;
bool hasSolution;
if (!solver->impl->computeInitialValues(query, objects, values,
hasSolution))
return false;
Assignment *binding;
if (hasSolution) {
binding = new Assignment(objects, values);
// Memoize the result.
std::pair<assignmentsTable_ty::iterator, bool>
res = assignmentsTable.insert(binding);
if (!res.second) {
delete binding;
binding = *res.first;
}
if (DebugCexCacheCheckBinding)
assert(binding->satisfies(key.begin(), key.end()));
} else {
binding = (Assignment*) 0;
}
result = binding;
cache.insert(key, binding);
return true;
}
示例12: setKey
void StringCipherWithPermutationKey::setKey(const KeyType &key)
{
if (key.empty())
{
throw EmptyKey("Your key is empty.");
}
if (!isUniqueWithoutMissingIntegers(key))
{
throw BadPermutationKey("Your permutation key has to contain unique integers and / or integers "
"between 0 and the size of your key have to be all there.");
}
this->key = key;
}
示例13: operator
std::string operator()( const KeyType& key ) const {
using data_type = typename KeyType::data_type;
constexpr int position = Storage::template position<KeyType>();
constexpr bool is_default = position == DefaultPosition;
checksummed_data<data_type> wrapper;
wrapper.data = key.serialize();
wrapper.check = checksummed_data<data_type>::calculate_checksum(wrapper.data, !is_default ? Prefixes[position] : nullptr);
auto packed = raw::pack( wrapper );
auto data_str = to_base58( packed.data(), packed.size() );
if (!is_default) {
data_str = string(Prefixes[position]) + "_" + data_str;
}
return data_str;
}
示例14: KeyType
/// lookupAssignment - Lookup a cached result for the given \arg query.
///
/// \param query - The query to lookup.
/// \param key [out] - On return, the key constructed for the query.
/// \param result [out] - The cached result, if the lookup is succesful. This is
/// either a satisfying assignment (for a satisfiable query), or 0 (for an
/// unsatisfiable query).
/// \return True if a cached result was found.
bool CexCachingSolver::lookupAssignment(const Query &query,
KeyType &key,
Assignment *&result) {
key = KeyType(query.constraints.begin(), query.constraints.end());
ref<Expr> neg = Expr::createIsZero(query.expr);
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(neg)) {
if (CE->isFalse()) {
result = (Assignment*) 0;
return true;
}
} else {
key.insert(neg);
}
return searchForAssignment(key, result);
}
示例15: getLocalKey
static constexpr LocalKeyType getLocalKey(const KeyType& k) {
return LocalKeyType(k.hash());
}