コード例 #1
0
ファイル: seq_num_index.cpp プロジェクト: Strongc/nark-db
	int seekLowerBound(fstring key, llong* id, valvec<byte>* retKey) override {
		assert(key.size() == sizeof(Int));
		if (key.size() != sizeof(Int)) {
			THROW_STD(invalid_argument,
				"key.size must be sizeof(Int)=%d", int(sizeof(Int)));
		}
		auto owner = static_cast<const SeqNumIndex*>(m_index.get());
		Int keyId = unaligned_load<Int>(key.udata());
		if (keyId <= owner->m_min) {
			m_curr = 0;
			return -1;
		}
		else if (keyId > owner->m_min + owner->m_cnt) {
			m_curr = owner->m_cnt;
			*id = owner->m_cnt - 1;
			Int forwardMax = owner->m_min + owner->m_cnt - 1;
			retKey->assign((const byte*)&forwardMax, sizeof(Int));
			return 1;
		}
		else {
			keyId -= owner->m_min;
			m_curr = keyId;
			*id = keyId;
			retKey->assign(key.udata(), key.size());
			return 0;
		}
	}
コード例 #2
0
ファイル: seq_num_index.cpp プロジェクト: Strongc/nark-db
bool SeqNumIndex<Int>::insert(fstring key, llong id, DbContext*) {
	assert(key.size() == sizeof(Int));
	assert(id >= 0);
	if (key.size() != sizeof(Int)) {
		THROW_STD(invalid_argument,
			"key.size must be sizeof(Int)=%d", int(sizeof(Int)));
	}
	Int keyId = unaligned_load<Int>(key.udata());
	if (keyId != m_min + id) {
		THROW_STD(invalid_argument,
			"key must be consistent with id in SeqNumIndex");
	}
	if (llong(m_cnt) < id + 1) {
		m_cnt = id + 1;
	}
	return 1;
}
コード例 #3
0
ファイル: seq_num_index.cpp プロジェクト: Strongc/nark-db
bool SeqNumIndex<Int>::replace(fstring key, llong id, llong newId, DbContext*) {
	assert(key.size() == sizeof(Int));
	assert(id >= 0);
	assert(id == newId);
	if (key.size() != sizeof(Int)) {
		THROW_STD(invalid_argument,
			"key.size must be sizeof(Int)=%d", int(sizeof(Int)));
	}
	if (id != newId) {
		THROW_STD(invalid_argument,
			"replace with different id is not supported by SeqNumIndex");
	}
	Int keyId = unaligned_load<Int>(key.udata());
	if (keyId != m_min + newId) {
		THROW_STD(invalid_argument,
			"key must be consistent with id in SeqNumIndex");
	}
	return 1;
}