コード例 #1
0
ファイル: var_int.cpp プロジェクト: career-tankles/scrawl
int64_t load_var_int64(const unsigned char* buf, const unsigned char** endp)
{
	return var_int64_u2s(load_var_uint64(buf, endp));
}
コード例 #2
0
void load(Archive& ar, febird::var_int64_t& x, unsigned ver)
{
	x.t = febird::var_int64_u2s(load_var_uint64(ar));
}
コード例 #3
0
ファイル: intkey_index.cpp プロジェクト: rockeet/nark-db
void ZipIntKeyIndex::build(ColumnType keyType, SortableStrVec& strVec) {
	assert(strVec.m_index.size() == 0);
	m_keyType = keyType;
	void*  data = strVec.m_strpool.data();
	size_t size = strVec.m_strpool.size();
	switch (keyType) {
	default:
		THROW_STD(invalid_argument, "Bad keyType=%s", Schema::columnTypeStr(keyType));
	case ColumnType::Sint08: zipKeys< int8_t >(data, size); break;
	case ColumnType::Uint08: zipKeys<uint8_t >(data, size); break;
	case ColumnType::Sint16: zipKeys< int16_t>(data, size); break;
	case ColumnType::Uint16: zipKeys<uint16_t>(data, size); break;
	case ColumnType::Sint32: zipKeys< int32_t>(data, size); break;
	case ColumnType::Uint32: zipKeys<uint32_t>(data, size); break;
	case ColumnType::Sint64: zipKeys< int64_t>(data, size); break;
	case ColumnType::Uint64: zipKeys<uint64_t>(data, size); break;
	case ColumnType::VarSint: {
		valvec<llong> tmp;
		const byte* pos = strVec.m_strpool.data();
		const byte* end = strVec.m_strpool.end();
		while (pos < end) {
			const byte* next = nullptr;
			llong key = load_var_int64(pos, &next);
			tmp.push_back(key);
			pos = next;
		}
		zipKeys<int64_t>(tmp.data(), tmp.used_mem_size());
		break; }
	case ColumnType::VarUint: {
		valvec<ullong> tmp;
		const byte* pos = strVec.m_strpool.data();
		const byte* end = strVec.m_strpool.end();
		while (pos < end) {
			const byte* next = nullptr;
			ullong key = load_var_uint64(pos, &next);
			tmp.push_back(key);
			pos = next;
		}
		zipKeys<uint64_t>(tmp.data(), tmp.used_mem_size());
		break; }
	}
	valvec<uint32_t> index(m_keys.size(), valvec_no_init());
	for (size_t i = 0; i < index.size(); ++i) index[i] = uint32_t(i);
	std::sort(index.begin(), index.end(), [&](size_t x, size_t y) {
		size_t xkey = m_keys.get(x);
		size_t ykey = m_keys.get(y);
		if (xkey < ykey) return true;
		if (xkey > ykey) return false;
		return x < y;
	});
	auto minIdx = m_index.build_from(index);
	(void)minIdx;
#if !defined(NDEBUG)
	assert(0 == minIdx);
	for(size_t i = 1; i < m_index.size(); ++i) {
		size_t xi = m_index.get(i-1);
		size_t yi = m_index.get(i-0);
		size_t xk = m_keys.get(xi);
		size_t yk = m_keys.get(yi);
		assert(xk <= yk);
	}
#endif
}