Esempio n. 1
0
bool Cmerkle_tree::test(int i, const_memory_range v, const_memory_range w)
{
	assert(i >= 0);
	assert(i < m_size);
	int a = 0;
	int b = m_size;
	unsigned int z = 0;
	const_memory_range h = v;
	while (1)
	{
		if (*d(a + i))
			return h.string() == get0(a + i).string();
		if (b - a < 2 || z + 20 > w.size())
			return false;
		int j = i ^ 1;
		if (a + j < b)
		{
			h = i < j ? internal_hash(h, w.sub_range(z, 20)) : internal_hash(w.sub_range(z, 20), h);
			z += 20;
		}
		int c = a;
		a = b;
		b += b - c + 1 >> 1;
		i >>= 1;
	}
}
Esempio n. 2
0
void Cmerkle_tree::set(int i, const_memory_range v, const_memory_range w)
{
	assert(i >= 0);
	assert(i < m_size);
	int a = 0;
	int b = m_size;
	unsigned int z = 0;
	set0(a + i, v);
	while (b - a >= 2 && z + 20 <= w.size())
	{
		int j = i ^ 1;
		if (a + j < b)
		{
			if (*d(a + j))
				return;
			set0(a + j, w.sub_range(z, 20));
			z += 20;
		}
		int c = a;
		a = b;
		b += b - c + 1 >> 1;
		i >>= 1;
	}
}