Example #1
0
 bool WorkflowJSON_Impl::checkForUpdates()
 {
   std::string h1 = hash();
   std::string h2 = computeHash();
   bool result = (h1 != h2);
   if (result){
     onUpdate();
     h2 = computeHash(); // recompute hash after updating timestamps in onUpdate
     m_value["hash"] = h2;
   }
   return result;
 }
Example #2
0
//==============================================================================
Error Material::createProgramSourceToCache(
	const TempResourceString& source, TempResourceString& out)
{
	Error err = ErrorCode::NONE;

	auto alloc = m_resources->_getTempAllocator();

	// Create the hash
	U64 h = computeHash(&source[0], source.getLength());
	TempResourceString prefix;
	TempResourceString::ScopeDestroyer prefixd(&prefix, alloc);

	ANKI_CHECK(prefix.toString(alloc, h));

	// Create path
	ANKI_CHECK(out.sprintf(alloc, "%s/mtl_%s.glsl", 
		&m_resources->_getCacheDirectory()[0],
		&prefix[0]));

	// If file not exists write it
	if(!fileExists(out.toCString()))
	{
		// If not create it
		File f;
		ANKI_CHECK(f.open(out.toCString(), File::OpenFlag::WRITE));
		ANKI_CHECK(f.writeText("%s\n", &source[0]));
	}

	return err;
}
Example #3
0
NetworkCacheKey::NetworkCacheKey(const String& method, const String& partition, const String& identifier)
    : m_method(method.isolatedCopy())
    , m_partition(partition.isolatedCopy())
    , m_identifier(identifier.isolatedCopy())
    , m_hash(computeHash())
{
}
Example #4
0
//------------------------------------------------------------------------------
void Solver::HashTable::Fill
(
    const IDList& particleIDs
)
{
    // clear all buckets
    for (unsigned int i = 0; i < mDomain.Dimensions.X*mDomain.Dimensions.Y; i++)
    {
        mBuckets[i].clear();
    }

    // fill buckets
    IDList::const_iterator i = particleIDs.begin();
    IDList::const_iterator e = particleIDs.end();

    for (; i != e; i++)
    {
        unsigned int hash = computeHash
                            (
                                Vector2f(&mPositions[2*(*i)]),
                                mDomain
                            );
        mBuckets[hash].push_back(*i);
    }

}
Example #5
0
void PipelineImpl::initDepthStencilState()
{
	const auto& ds = m_in.m_depthStencil;

	// Depth
	m_cache.m_depthCompareFunction = convertCompareOperation(ds.m_depthCompareFunction);

	// Stencil
	m_cache.m_stencilFailOp[0] = convertStencilOperation(ds.m_stencilFront.m_stencilFailOperation);
	m_cache.m_stencilPassDepthFailOp[0] = convertStencilOperation(ds.m_stencilFront.m_stencilPassDepthFailOperation);
	m_cache.m_stencilPassDepthPassOp[0] = convertStencilOperation(ds.m_stencilFront.m_stencilPassDepthPassOperation);
	m_cache.m_stencilCompareFunc[0] = convertCompareOperation(ds.m_stencilFront.m_compareFunction);

	m_cache.m_stencilFailOp[1] = convertStencilOperation(ds.m_stencilBack.m_stencilFailOperation);
	m_cache.m_stencilPassDepthFailOp[1] = convertStencilOperation(ds.m_stencilBack.m_stencilPassDepthFailOperation);
	m_cache.m_stencilPassDepthPassOp[1] = convertStencilOperation(ds.m_stencilBack.m_stencilPassDepthPassOperation);
	m_cache.m_stencilCompareFunc[1] = convertCompareOperation(ds.m_stencilBack.m_compareFunction);

	if(stencilTestDisabled(ds.m_stencilFront) && stencilTestDisabled(ds.m_stencilBack))
	{
		m_stencilTestEnabled = false;
	}
	else
	{
		m_stencilTestEnabled = true;
	}

	m_hashes.m_depthStencil = computeHash(&ds, sizeof(ds));
}
Example #6
0
void PipelineImpl::initRasterizerState()
{
	switch(m_in.m_rasterizer.m_fillMode)
	{
	case FillMode::POINTS:
		m_cache.m_fillMode = GL_POINT;
		break;
	case FillMode::WIREFRAME:
		m_cache.m_fillMode = GL_LINE;
		break;
	case FillMode::SOLID:
		m_cache.m_fillMode = GL_FILL;
		break;
	default:
		ANKI_ASSERT(0);
	}

	switch(m_in.m_rasterizer.m_cullMode)
	{
	case FaceSelectionMask::FRONT:
		m_cache.m_cullMode = GL_FRONT;
		break;
	case FaceSelectionMask::BACK:
		m_cache.m_cullMode = GL_BACK;
		break;
	case FaceSelectionMask::FRONT_AND_BACK:
		m_cache.m_cullMode = GL_FRONT_AND_BACK;
		break;
	default:
		ANKI_ASSERT(0);
	}

	m_hashes.m_rasterizer = computeHash(&m_in.m_rasterizer, sizeof(m_in.m_rasterizer));
}
Example #7
0
void PipelineImpl::initInputAssemblerState()
{
	switch(m_in.m_inputAssembler.m_topology)
	{
	case PrimitiveTopology::POINTS:
		m_cache.m_topology = GL_POINTS;
		break;
	case PrimitiveTopology::LINES:
		m_cache.m_topology = GL_LINES;
		break;
	case PrimitiveTopology::LINE_STIP:
		m_cache.m_topology = GL_LINE_STRIP;
		break;
	case PrimitiveTopology::TRIANGLES:
		m_cache.m_topology = GL_TRIANGLES;
		break;
	case PrimitiveTopology::TRIANGLE_STRIP:
		m_cache.m_topology = GL_TRIANGLE_STRIP;
		break;
	case PrimitiveTopology::PATCHES:
		m_cache.m_topology = GL_PATCHES;
		break;
	default:
		ANKI_ASSERT(0);
	}

	m_hashes.m_inputAssembler = computeHash(&m_in.m_inputAssembler, sizeof(m_in.m_inputAssembler));
}
Example #8
0
//------------------------------------------------------------------------------
void Solver::HashTable::Query (const Vector2f& position, float range)
{
    // reset previous result
    mResult.clear();

    Vector2f begf(position);
    begf.X -= range;
    begf.Y -= range;
    Vector2f endf(position);
    endf.X += range;
    endf.Y += range;

    Vector2ui beg = computeCoordinate(begf, mDomain);
    Vector2ui end = computeCoordinate(endf, mDomain);

    for (unsigned int i = beg.X; i <= end.X; i++)
    {
        for (unsigned int j = beg.Y; j <= end.Y; j++)
        {
            unsigned int hash = computeHash(i, j, mDomain.Dimensions.X);
            mResult.insert
            (
                mResult.end(),
                mBuckets[hash].begin(),
                mBuckets[hash].end()
            );
        }
    }
}
Example #9
0
static
pt_value *contextElement(pt_context *context, char *name) {
	extern pt_value UNDEF;

	pt_context_node *node = context->tail;
	pt_context_elem *elem = node->head;
	int hash = computeHash(name);

	while(elem != NULL) {
		if(elem->hash == hash) {
			return &elem->value;
		}
	}

	elem = createContextElem(UNDEF);
	if(elem == NULL) return NULL;

	elem->hash = hash;
	if(node->tail != NULL) {
		node->head = node->tail = elem;
	} else {
		node->tail->next = elem;
		node->tail = elem;
	}

	return &elem->value;
}
Example #10
0
QByteArray HashFile::toHashFileContent()
{
    if (m_hash.isEmpty())
        if (!computeHash())
            return QByteArray();

    return m_hash.toHex() + QByteArray("  ") + m_fileName.toUtf8() + QByteArray("\n");
}
Example #11
0
DisassemblyData::DisassemblyData(u32 _address, u32 _size, DataType _type): address(_address), size(_size), type(_type)
{
	auto memLock = Memory::Lock();
	if (!PSP_IsInited())
		return;

	hash = computeHash(address,size);
	createLines();
}
void DisassemblyData::recheck()
{
	u32 newHash = computeHash(address,size);
	if (newHash != hash)
	{
		hash = newHash;
		createLines();
	}
}
Example #13
0
DisassemblyFunction::DisassemblyFunction(u32 _address, u32 _size): address(_address), size(_size)
{
	auto memLock = Memory::Lock();
	if (!PSP_IsInited())
		return;

	hash = computeHash(address,size);
	load();
}
Example #14
0
unsigned Register::getHash() const {
    switch (type) {
        case Types::Tag::Integer:
            return intValue;
        case Types::Tag::Char:
            return computeHash(stringValue.data(), stringValue.length());
    }
    return 0;
}
void DisassemblyFunction::recheck()
{
	u32 newHash = computeHash(address,size);
	if (hash != newHash)
	{
		hash = newHash;
		clear();
		load();
	}
}
/** Compute Tor SAFECOOKIE response.
 *
 *    ServerHash is computed as:
 *      HMAC-SHA256("Tor safe cookie authentication server-to-controller hash",
 *                  CookieString | ClientNonce | ServerNonce)
 *    (with the HMAC key as its first argument)
 *
 *    After a controller sends a successful AUTHCHALLENGE command, the
 *    next command sent on the connection must be an AUTHENTICATE command,
 *    and the only authentication string which that AUTHENTICATE command
 *    will accept is:
 *
 *      HMAC-SHA256("Tor safe cookie authentication controller-to-server hash",
 *                  CookieString | ClientNonce | ServerNonce)
 *
 */
static std::vector<uint8_t> ComputeResponse(const std::string &key, const std::vector<uint8_t> &cookie,  const std::vector<uint8_t> &clientNonce, const std::vector<uint8_t> &serverNonce)
{
    CHMAC_SHA256 computeHash((const uint8_t*)key.data(), key.size());
    std::vector<uint8_t> computedHash(CHMAC_SHA256::OUTPUT_SIZE, 0);
    computeHash.Write(begin_ptr(cookie), cookie.size());
    computeHash.Write(begin_ptr(clientNonce), clientNonce.size());
    computeHash.Write(begin_ptr(serverNonce), serverNonce.size());
    computeHash.Finalize(begin_ptr(computedHash));
    return computedHash;
}
Example #17
0
ExceptionOr<void> CryptoAlgorithmSHA1::digest(const CryptoAlgorithmParametersDeprecated&, const CryptoOperationData& data, VectorCallback&& callback, VoidCallback&& failureCallback)
{
    auto digest = CryptoDigest::create(CryptoDigest::Algorithm::SHA_1);
    if (!digest) {
        failureCallback();
        return { };
    }
    digest->addBytes(data.first, data.second);
    callback(digest->computeHash());
    return { };
}
Example #18
0
// Find inside hash set
int HashSet_find(HashSet* h,const char* word,size_t len) {
	int32_t hash=computeHash(word,len);
	int64_t slot=hash&h->mask;
	const Entry* e = &h->table[slot];
	if (!Entry_isDeleted(e)) do {
		if (e->hash == hash) return true;
		slot = (slot + 1) & h->mask;
		e = &h->table[slot];
	} while (!Entry_isDeleted(e));
    return false;
}
Example #19
0
//------------------------------------------------------------------------------
inline unsigned int computeHash
(
    const Vector2f& position,
    const Domain& domain
)
{
    return computeHash
           (
               computeCoordinate(position, domain),
               domain.Dimensions.X
           );
}
Example #20
0
void DisassemblyData::recheck()
{
	auto memLock = Memory::Lock();
	if (!PSP_IsInited())
		return;

	u32 newHash = computeHash(address,size);
	if (newHash != hash)
	{
		hash = newHash;
		createLines();
	}
}
Example #21
0
static void addEntryToHashTable(HashTable* pHash, ZipEntry* pEntry)
{
    unsigned int itemHash = computeHash(pEntry->fileName, pEntry->fileNameLen);
    const ZipEntry* found;

    found = (const ZipEntry*)mzHashTableLookup(pHash,
                itemHash, pEntry, hashcmpZipEntry, true);
    if (found != pEntry) {
        LOGW("WARNING: duplicate entry '%.*s' in Zip\n",
            found->fileNameLen, found->fileName);
        /* keep going */
    }
}
Example #22
0
void DisassemblyFunction::recheck()
{
	auto memLock = Memory::Lock();
	if (!PSP_IsInited())
		return;

	u32 newHash = computeHash(address,size);
	if (hash != newHash)
	{
		hash = newHash;
		clear();
		load();
	}
}
Example #23
0
      SET_NODE *internalAdd(const ObjType &u) {
        int hashval = computeHash(u);

        // look for this object in the appropriate linked list
        for (SET_NODE* p=hashTable[hashval]; p!=0; p=p->next)
          if (p->u==u) return 0;                 // already a member
    
        // create new node and stick at head of linked list
        SET_NODE *sn = createNode(u);
        sn->idx  = currentSize;
        sn->next = hashTable[hashval];
        hashTable[hashval] = sn;    
        return sn;
      }
Example #24
0
 int internalRemove(const ObjType &u) {
   // returns index of extracted object, or -1 if not there.
   int hashval = computeHash(u);
   SET_NODE* sn = hashTable[hashval];
   SET_NODE** pLast = &(hashTable[hashval]);
   while (sn) {
     if (sn->u == u) {
       int idx = sn->idx;
       *pLast = sn->next;
       deleteNode(sn);
       return idx;
     }
     pLast = &(sn->next);
     sn = sn->next;
   }
   return -1;
 }
Example #25
0
/*
 * The algorithm of RendezvousHash goes like this:
 * Assuming we have 3 clusters with names and weights:
 * ==============================================
 * | Cluster1     | Cluster2     | Cluster3     |
 * | n="cluster1" | n="cluster2" | n="cluster3" |
 * | w=100        | w=400        | w=500        |
 * ==============================================
 * To prepare, we calculate a hash for each cluster based on its name:
 * ==============================================
 * | Cluster1     | Cluster2     | Cluster3     |
 * | n="cluster1" | n="cluster2" | n="cluster3" |
 * | w = 100      | w=400        | w=500        |
 * | h = hash(n)  | h = hash(n)  | h = hash(n)  |
 * ==============================================
 *
 * When a key comes, we have to decide which cluster we want to assign it to:
 * E.g., k = 10240
 *
 * For each cluster, we calculate a combined hash with the sum of key
 * and the cluster's hash:
 *
 *
 *                             ==============================================
 *                             | Cluster1     | Cluster2     | Cluster3     |
 *                                               ...
 *        k                    | h=hash(n)    | h = hash(n)  | h=hash(n)    |
 *        |                    ==============================================
 *        |                                          |
 *        +-------------+----------------------------+
 *                      |
 *                  ch=hash(h + k)
 *                      |
 *                      v
 * ==============================================
 * | Cluster1     | Cluster2     | Cluster3     |
 * | n="cluster1" | n="cluster2" | n="cluster3" |
 * | w=100        | w=400        | w=500        |
 * | h=hash(n)    | h = hash(n)  | h=hash(n)    |
 * |ch=hash(h+k)  |ch = hash(h+k)|ch=hash(h+k)  |
 * ==============================================
 *
 * ch is now a random variable from 0 to max_int that follows
 * uniform distribution,
 * we need to scale it to a r.v. * from 0 to 1 by dividing it with max_int:
 *
 * scaledHash = ch / max_int
 *
 * ==============================================
 * | Cluster1     | Cluster2     | Cluster3     |
 *                    ....
 * |ch=hash(h+k)  |ch = hash(h+k)|ch=hash(h+k)  |
 * ==============================================
 *                      |
 *                    sh=ch/max_int
 *                      |
 *                      v
 * ==============================================
 * | Cluster1     | Cluster2     | Cluster3     |
 *                    ....
 * |ch=hash(h+k)  |ch = hash(h+k)|ch=hash(h+k)  |
 * |sh=ch/max_int |sh=ch/max_int |sh=ch/max_int |
 * ==============================================
 *
 * We also need to respect the weights, we have to scale it again with
 * a function of its weight:
 *
 * ==============================================
 * | Cluster1     | Cluster2     | Cluster3     |
 *                    ....
 * |sh=ch/max_int |sh=ch/max_int |sh=ch/max_int |
 * ==============================================
 *                      |
 *                      |
 *               sw = pow(sh, 1/w)
 *                      |
 *                      V
 * ==============================================
 * | Cluster1     | Cluster2     | Cluster3     |
 *                    ....
 * |sh=ch/max_int |sh=ch/max_int |sh=ch/max_int |
 * |sw=pow(sh,1/w)|sw=pow(sh,1/w)|sw=pow(sh,1/w)|
 * ==============================================
 *
 * We now calculate who has the largest sw, that is the cluster that we are
 * going to map k into:
 * ==============================================
 * | Cluster1     | Cluster2     | Cluster3     |
 *                    ....
 * |sw=pow(sh,1/w)|sw=pow(sh,1/w)|sw=pow(sh,1/w)|
 * ==============================================
 *                      |
 *                     max(sw)
 *                      |
 *                      V
 *                   Cluster
 *
 */
size_t RendezvousHash::get(uint64_t key) const {
  double maxWeight = -1.0;
  size_t maxWeightId = 0;
  for (size_t i = 0; i < nodes_.size(); ++i) {
    auto& it = nodes_[i];
    // combine the hash with the cluster together
    double combinedHash = computeHash(it.first + key);
    double scaledHash = combinedHash / std::numeric_limits<uint64_t>::max();
    double scaledWeight = it.second > std::numeric_limits<double>::epsilon()
      ? std::pow(scaledHash, 1.0 / it.second)
      : 0.0;
    if (scaledWeight > maxWeight) {
      maxWeightId = i;
      maxWeight = scaledWeight;
    }
  }
  return maxWeightId;
}
Example #26
0
void CryptoAlgorithmSHA1::digest(Vector<uint8_t>&& message, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
{
    auto digest = CryptoDigest::create(CryptoDigest::Algorithm::SHA_1);
    if (!digest) {
        exceptionCallback(OperationError);
        return;
    }

    context.ref();
    workQueue.dispatch([digest = WTFMove(digest), message = WTFMove(message), callback = WTFMove(callback), &context]() mutable {
        digest->addBytes(message.data(), message.size());
        auto result = digest->computeHash();
        context.postTask([callback = WTFMove(callback), result = WTFMove(result)](ScriptExecutionContext& context) {
            callback(result);
            context.deref();
        });
    });
}
Example #27
0
void PipelineImpl::initColorState()
{
	for(U i = 0; i < m_in.m_color.m_attachmentCount; ++i)
	{
		Attachment& out = m_cache.m_attachments[i];
		const ColorAttachmentStateInfo& in = m_in.m_color.m_attachments[i];

		out.m_srcBlendMethod = convertBlendMethod(in.m_srcBlendMethod);
		out.m_dstBlendMethod = convertBlendMethod(in.m_dstBlendMethod);

		switch(in.m_blendFunction)
		{
		case BlendFunction::ADD:
			out.m_blendFunction = GL_FUNC_ADD;
			break;
		case BlendFunction::SUBTRACT:
			out.m_blendFunction = GL_FUNC_SUBTRACT;
			break;
		case BlendFunction::REVERSE_SUBTRACT:
			out.m_blendFunction = GL_FUNC_REVERSE_SUBTRACT;
			break;
		case BlendFunction::MIN:
			out.m_blendFunction = GL_MIN;
			break;
		case BlendFunction::MAX:
			out.m_blendFunction = GL_MAX;
			break;
		default:
			ANKI_ASSERT(0);
		}

		out.m_channelWriteMask[0] = (in.m_channelWriteMask & ColorBit::RED) != 0;
		out.m_channelWriteMask[1] = (in.m_channelWriteMask & ColorBit::GREEN) != 0;
		out.m_channelWriteMask[2] = (in.m_channelWriteMask & ColorBit::BLUE) != 0;
		out.m_channelWriteMask[3] = (in.m_channelWriteMask & ColorBit::ALPHA) != 0;

		if(!(out.m_srcBlendMethod == GL_ONE && out.m_dstBlendMethod == GL_ZERO))
		{
			m_blendEnabled = true;
		}
	}

	m_hashes.m_color = computeHash(&m_in.m_color, sizeof(m_in.m_color));
}
Example #28
0
pt_value resolveSymbol(pt_context *context, char *name) {
	extern pt_value UNDEF;

	pt_context_node *node = context->tail;
	int hash = computeHash(name);

	while(node != NULL) {
		pt_context_elem *elem = node->head;

		while(elem != NULL) {
			if(elem->hash == hash) {
				return elem->value;
			}
		}

		node = node->prev;
	}

	return UNDEF;
}
Example #29
0
//------------------------------------------------------------------------------
void Solver::HashTable::Fill (unsigned int numParticles)
{
    // clear all buckets
    for (unsigned int i = 0; i < mDomain.Dimensions.X*mDomain.Dimensions.Y; i++)
    {
        mBuckets[i].clear();
    }

    // fill buckets
    for (unsigned int i = 0; i < numParticles; i++)
    {
        unsigned int hash = computeHash
                            (
                                Vector2f(&mPositions[2*i]),
                                mDomain
                            );
        mBuckets[hash].push_back(i);
    }

}
Example #30
0
/*
 * Find a matching entry.
 *
 * Returns 0 if not found.
 */
ZipEntry dexZipFindEntry(const ZipArchive* pArchive, const char* entryName)
{
    int nameLen = strlen(entryName);
    unsigned int hash = computeHash(entryName, nameLen);
    const int hashTableSize = pArchive->mHashTableSize;
    int ent = hash & (hashTableSize-1);

    while (pArchive->mHashTable[ent].name != NULL) {
        if (pArchive->mHashTable[ent].nameLen == nameLen &&
            memcmp(pArchive->mHashTable[ent].name, entryName, nameLen) == 0)
        {
            /* match */
            return (ZipEntry)(long)(ent + kZipEntryAdj);
        }

        ent = (ent + 1) & (hashTableSize-1);
    }

    return NULL;
}