コード例 #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
ファイル: intkey_index.cpp プロジェクト: rockeet/nark-db
std::pair<size_t, bool>
ZipIntKeyIndex::IntVecLowerBound(fstring binkey) const {
	assert(binkey.size() == sizeof(Int));
	Int rawkey = unaligned_load<Int>(binkey.data());
	if (rawkey < Int(m_minKey)) {
		return std::make_pair(0, false);
	}
	auto indexData = m_index.data();
	auto indexBits = m_index.uintbits();
	auto indexMask = m_index.uintmask();
	auto keysData = m_keys.data();
	auto keysBits = m_keys.uintbits();
	auto keysMask = m_keys.uintmask();
	size_t key = size_t(rawkey - Int(m_minKey));
	size_t hitPos = 0;
	size_t hitKey = 0;
	size_t i = 0, j = m_index.size();
	while (i < j) {
		size_t mid = (i + j) / 2;
		hitPos = UintVecMin0::fast_get(indexData, indexBits, indexMask, mid);
		hitKey = UintVecMin0::fast_get(keysData, keysBits, keysMask, hitPos);
		if (hitKey < key)
			i = mid + 1;
		else
			j = mid;
	}
	if (i < m_index.size()) {
		hitPos = UintVecMin0::fast_get(indexData, indexBits, indexMask, i);
		hitKey = UintVecMin0::fast_get(keysData, keysBits, keysMask, hitPos);
		return std::make_pair(i, key == hitKey);
	}
	return std::make_pair(i, false);
}
コード例 #3
0
ファイル: FUFileManager.cpp プロジェクト: tweakoz/orkid
fstring FUFileManager::ExtractNetworkHostname(fstring& filename)
{
	fstring hostname;
#ifdef WIN32
	// UNC network paths are only supported on WIN32, right now.
	if (filename.size() > 2 && (filename[0] == '/' || filename[0] == '\\') && filename[1] == filename[0])
	{
		size_t nextSlash = min(filename.find('/', 2), filename.find('\\', 2));
		FUAssert(nextSlash != fstring::npos, return hostname); // The UNC patch should always have at least one network path
		hostname = filename.substr(2, nextSlash - 2);
		filename.erase(0, nextSlash); // Keep the slash to indicate absolute path.
	}
コード例 #4
0
ファイル: intkey_index.cpp プロジェクト: rockeet/nark-db
std::pair<size_t, size_t>
ZipIntKeyIndex::IntVecEqualRange(fstring binkey) const {
	assert(binkey.size() == sizeof(Int));
	Int rawkey = unaligned_load<Int>(binkey.data());
	if (rawkey < Int(m_minKey)) {
		return std::make_pair(0, false);
	}
	auto indexData = m_index.data();
	auto indexBits = m_index.uintbits();
	auto indexMask = m_index.uintmask();
	auto keysData = m_keys.data();
	auto keysBits = m_keys.uintbits();
	auto keysMask = m_keys.uintmask();
	size_t key = size_t(rawkey - Int(m_minKey));
	size_t i = 0, j = m_index.size();
	size_t mid = 0;
	while (i < j) {
		mid = (i + j) / 2;
		size_t hitPos = UintVecMin0::fast_get(indexData, indexBits, indexMask, mid);
		size_t hitKey = UintVecMin0::fast_get(keysData, keysBits, keysMask, hitPos);
		if (hitKey < key)
			i = mid + 1;
		else if (hitKey > key)
			j = mid;
		else
			goto Found;
	}
	return std::make_pair(i, i);
Found:
	size_t lo = i, hi = mid;
	while (lo < hi) {
		size_t mid2 = (lo + hi) / 2;
		size_t hitPos = UintVecMin0::fast_get(indexData, indexBits, indexMask, mid2);
		size_t hitKey = UintVecMin0::fast_get(keysData, keysBits, keysMask, hitPos);
		if (hitKey < key) // for lower_bound
			lo = mid2 + 1;
		else
			hi = mid2;
	}
	i = lo;
	lo = mid + 1, hi = j;
	while (lo < hi) {
		size_t mid2 = (lo + hi) / 2;
		size_t hitPos = UintVecMin0::fast_get(indexData, indexBits, indexMask, mid2);
		size_t hitKey = UintVecMin0::fast_get(keysData, keysBits, keysMask, hitPos);
		if (hitKey <= key) // for upper_bound
			lo = mid2 + 1;
		else
			hi = mid2;
	}
	return std::make_pair(i, hi);
}
コード例 #5
0
ファイル: match_key_l.cpp プロジェクト: career-tankles/scrawl
	void operator()(int len, int idx, fstring value) {
		if (strnlen(value.p, value.n) < value.size()) {
			printf("%-20.*s idx=%08d bin=", len, text, idx);
			for (int i = 0; i < value.n; ++i)
				printf("%02X", (byte_t)value.p[i]);
			printf("\n");
		}
		else {
			printf("%-20.*s idx=%08d val=%.*s\n"
				, len, text, idx, value.ilen(), value.data());
		}
		klen = len;
	}
コード例 #6
0
ファイル: FCTest.cpp プロジェクト: Marlinc/0ad
int main(int argc, char* argv[])
{
	ProcessCommandLine(argc, argv);
	FCollada::Initialize(); //Needed for Mac/Linux when FCollada is statically linked.
	// In debug mode, output memory leak information and do periodic memory checks
#ifdef PLUG_CRT
	_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF | _CRTDBG_CHECK_EVERY_128_DF);
#endif

	FUTestBed testBed(logFilename.c_str(), isVerbose);

#ifndef _DEBUG
	try {
#endif
	// Set the current folder to the folder with the samples DAE files
	_chdir("Samples");

	// FMath tests
	RUN_TESTSUITE(FCTestAll)

#ifndef _DEBUG
	}
	catch (const char* sz) { testBed.GetLogFile().WriteLine(sz); }
#ifdef UNICODE
	catch (const fchar* sz) { testBed.GetLogFile().WriteLine(sz); }
#endif
	catch (...) { testBed.GetLogFile().WriteLine("Exception caught!"); }
#endif

	return 0;
}
コード例 #7
0
	bool indexInsert(size_t indexId, fstring key, llong recId) override {
		assert(started == m_status);
		assert(indexId < m_indices.size());
		WT_ITEM item;
		WT_SESSION* ses = m_session.ses;
		const Schema& schema = m_sconf.getIndexSchema(indexId);
		WT_CURSOR* cur = m_indices[indexId].insert;
		WtWritableIndex::setKeyVal(schema, cur, key, recId, &item, &m_wrtBuf);
		int err = cur->insert(cur);
		m_sizeDiff += sizeof(llong) + key.size();
		if (schema.m_isUnique) {
			if (WT_DUPLICATE_KEY == err) {
				return false;
			}
			if (err) {
				THROW_STD(invalid_argument
					, "ERROR: wiredtiger insert unique index: %s", ses->strerror(ses, err));
			}
		}
		else {
			if (WT_DUPLICATE_KEY == err) {
				assert(0); // assert in debug
				return true; // ignore in release
			}
			if (err) {
				THROW_STD(invalid_argument
					, "ERROR: wiredtiger insert multi index: %s", ses->strerror(ses, err));
			}
		}
		return true;
	}
コード例 #8
0
ファイル: mock_db_engine.cpp プロジェクト: Strongc/nark-db
llong MockWritableSegment::append(fstring row, DbContext*) {
	llong id = m_rows.size();
	m_rows.push_back();
	m_rows.back().assign(row);
	m_dataSize += row.size();
	return id;
}
コード例 #9
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;
}
コード例 #10
0
llong MockWritableStore::append(fstring row, DbContext*) {
	SpinRwLock lock(m_rwMutex, true);
	llong id = m_rows.size();
	m_rows.push_back();
	m_rows.back().assign(row);
	m_dataSize += row.size();
	return id;
}
コード例 #11
0
ファイル: mock_db_engine.cpp プロジェクト: Strongc/nark-db
void MockWritableSegment::replace(llong id, fstring row, DbContext*) {
	assert(id >= 0);
	assert(id < llong(m_rows.size()));
	size_t oldsize = m_rows[id].size();
	m_rows[id].assign(row);
	m_dataSize -= oldsize;
	m_dataSize += row.size();
}
コード例 #12
0
ファイル: FUUri.cpp プロジェクト: tweakoz/orkid
FUUri::FUUri(const fstring uri, bool escape)
	:	scheme(FUUri::NONE),
		port(0),
		path(FC(""))
{
	if (uri.empty()) return;

	fstring _uri;

	if (escape)
	{
		_uri = Escape(uri);
	}
	else
	{
		_uri = uri;
	}

	// Replace all '\\' characters by '/' so the path is only using them
	//_uri.replace(FC('\\'), FC('/'));
	
	_uri = FixFuxedUpColladaPaths( _uri );

	// Find the scheme from its ':' delimiter
	size_t schemeDelimiterIndex = _uri.find(FC(':'));
	size_t hostIndex = 0;

	if (schemeDelimiterIndex != fstring::npos && schemeDelimiterIndex > 1)
	{
		fstring _scheme = _uri.substr(0, schemeDelimiterIndex);

		if (IsEquivalent(_scheme, FC("FILE")) || IsEquivalent(_scheme, FC("file")))
		{
			scheme = FUUri::FILE;
		}
		else if (IsEquivalent(_scheme, FC("FTP")) || IsEquivalent(_scheme, FC("ftp")))
		{
			scheme = FUUri::FTP;
		}
		else if (IsEquivalent(_scheme, FC("HTTP")) || IsEquivalent(_scheme, FC("http")))
		{
			scheme = FUUri::HTTP;
		}
		else if (IsEquivalent(_scheme, FC("HTTPS")) || IsEquivalent(_scheme, FC("https")))
		{
			scheme = FUUri::HTTPS;
		}
		else
		{
#ifdef WIN32
			// Scheme not supported (could be a NFS path)
			FUFail(return);
#endif // WIN32
		}

		schemeDelimiter = _uri.substr(schemeDelimiterIndex, 3);
		hostIndex = schemeDelimiterIndex + 3;
	}
コード例 #13
0
ファイル: linebuf.hpp プロジェクト: CovariantStudio/terark-db
	size_t split_by_any(fstring delims, Vec* F, size_t max_fields = ~size_t(0)) {
		size_t dlen = delims.size();
		if (0 == dlen) // empty delims redirect to blank delim
			return split(' ', F);
		if (1 == dlen)
			return split(delims[0], F);
		F->resize(0);
		char *col = p, *end = p + n;
		while (col <= end && F->size()+1 < max_fields) {
			char* next = col;
			while (next < end && memchr(delims.data(), *next, dlen) == NULL) ++next;
			F->push_back(typename Vec::value_type(col, next));
			*next = 0;
			col = next + 1;
		}
		if (col <= end)
			F->push_back(typename Vec::value_type(col, end));
		return F->size();
	}
コード例 #14
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;
}
コード例 #15
0
ファイル: linebuf.hpp プロジェクト: CovariantStudio/terark-db
	size_t split(fstring delims, Vec* F, size_t max_fields = ~size_t(0)) {
		size_t dlen = delims.size();
		if (0 == dlen) // empty delims redirect to blank delim
			return split(' ', F);
		if (1 == dlen)
			return split(delims[0], F);
		F->resize(0);
		char *col = p, *end = p + n;
		while (col <= end && F->size()+1 < max_fields) {
			char* next = (char*)memmem(col, end-col, delims.data(), dlen);
			if (NULL == next) next = end;
			F->push_back(typename Vec::value_type(col, next));
			*next = 0;
			col = next + dlen;
		}
		if (col <= end)
			F->push_back(typename Vec::value_type(col, end));
		return F->size();
	}
コード例 #16
0
ファイル: FUFileManager.cpp プロジェクト: tweakoz/orkid
// Strip a full filename of its filename, returning the path
fstring FUFileManager::StripFileFromPath(const fstring& filename)
{
	fchar fullPath[MAX_PATH + 1];
	fstrncpy(fullPath, filename.c_str(), MAX_PATH);
	fullPath[MAX_PATH] = 0;
	fchar* lastSlash = fstrrchr(fullPath, FC('/'));
	fchar* lastBackslash = fstrrchr(fullPath, FC('\\'));
	lastSlash = max(lastSlash, lastBackslash);
	if (lastSlash != NULL) *(lastSlash + 1) = 0;
	return fstring(fullPath);
}
コード例 #17
0
void MockWritableStore::update(llong id, fstring row, DbContext* ctx) {
	assert(id >= 0);
	assert(id <= llong(m_rows.size()));
	if (llong(m_rows.size()) == id) {
		append(row, ctx);
		return;
	}
	SpinRwLock lock(m_rwMutex, true);
	size_t oldsize = m_rows[id].size();
	m_rows[id].assign(row);
	m_dataSize -= oldsize;
	m_dataSize += row.size();
}
コード例 #18
0
ファイル: FUFileManager.cpp プロジェクト: tweakoz/orkid
// Extract the file extension out of a filename
fstring FUFileManager::GetFileExtension(const fstring& _filename)
{
	fchar filename[MAX_PATH];
	fstrncpy(filename, _filename.c_str(), MAX_PATH);
	filename[MAX_PATH - 1] = 0;

	fchar* lastPeriod = fstrrchr(filename, '.');
	if (lastPeriod == NULL) return emptyFString;

	fchar* lastSlash = fstrrchr(filename, '/');
	fchar* lastBackslash = fstrrchr(filename, '\\');
	lastSlash = max(lastSlash, lastBackslash);
	if (lastSlash > lastPeriod) return emptyFString;

	fstrlower(lastPeriod + 1);	// [claforte] Untested on __PPU__, refer to definition of fstrlower.
	return fstring(lastPeriod + 1);
}
コード例 #19
0
ファイル: intkey_index.cpp プロジェクト: rockeet/nark-db
	int seekLowerBound(fstring key, llong* id, valvec<byte>* retKey) override {
		std::pair<size_t, bool> ib;
		if (key.empty())
			ib = std::make_pair(0, false);
		else
			ib = m_owner->searchLowerBound(key);
		m_keyIdx = ib.first;
		if (ib.first < m_owner->m_index.size()) {
			*id = m_owner->m_index.get(ib.first);
			if (retKey) {
				retKey->erase_all();
				m_owner->getValueAppend(*id, retKey, nullptr);
			}
			m_keyIdx++;
			return ib.second ? 0 : 1;
		}
		return -1;
	}
コード例 #20
0
ファイル: intkey_index.cpp プロジェクト: rockeet/nark-db
	int seekLowerBound(fstring key, llong* id, valvec<byte>* retKey) override {
		std::pair<size_t, bool> ib;
		if (key.empty())
			ib = std::make_pair(m_owner->m_index.size(), false);
		else
			ib = m_owner->searchLowerBound(key);
		m_keyIdx = ib.first;
		if (ib.first > 0 || ib.second) {
			if (!ib.second)
				--m_keyIdx; // backward next is backward-greater than key
			*id = m_owner->m_index[m_keyIdx];
			if (retKey) {
				retKey->erase_all();
				m_owner->getValueAppend(*id, retKey, nullptr);
			}
			return ib.second ? 0 : 1;
		}
		return -1;
	}
コード例 #21
0
ファイル: mock_db_engine.cpp プロジェクト: Strongc/nark-db
//static
int MockReadonlyIndex::forwardLowerBound(fstring key, size_t* pLower) const {
	const uint32_t* index = m_ids.data();
	const size_t rows = m_ids.size();
	const size_t fixlen = m_fixedLen;
	if (fixlen) {
		assert(m_keys.size() == 0);
		assert(key.size() == fixlen);
		FixedLenKeyCompare cmp;
		cmp.fixedLen = fixlen;
		cmp.strpool = m_keys.strpool.data();
		cmp.schema = m_schema;
		size_t lo = nark::lower_bound_0(index, rows, key, cmp);
		*pLower = lo;
		if (lo < rows) {
			size_t jj = m_ids[lo];
			if (key == fstring(cmp.strpool + fixlen*jj, fixlen))
				return 0;
			else
				return 1;
		}
	}
	else {
		VarLenKeyCompare cmp;
		cmp.offsets = m_keys.offsets.data();
		cmp.strpool = m_keys.strpool.data();
		cmp.schema = m_schema;
		size_t lo = nark::lower_bound_0(index, rows, key, cmp);
		*pLower = lo;
		if (lo < rows) {
			size_t jj = m_ids[lo];
			if (key == m_keys[jj])
				return 0;
			else
				return 1;
		}
	}
	return -1;
}
コード例 #22
0
//static
int MockReadonlyIndex::forwardLowerBound(fstring key, size_t* pLower) const {
	const uint32_t* index = m_ids.data();
	const size_t rows = m_ids.size();
	const size_t fixlen = m_fixedLen;
	const auto   cmp = m_schema->compareData_less();
	if (fixlen) {
		assert(m_keys.size() == 0);
		assert(key.size() == fixlen);
		FixedLenKeyExtractor keyEx;
		keyEx.fixedLen = fixlen;
		keyEx.strpool = m_keys.strpool.data();
		size_t lo = lower_bound_ex_0(index, rows, key, keyEx, cmp);
		*pLower = lo;
		if (lo < rows) {
			size_t jj = m_ids[lo];
			if (key == fstring(keyEx.strpool + fixlen*jj, fixlen))
				return 0;
			else
				return 1;
		}
	}
	else {
		VarLenKeyExtractor keyEx;
		keyEx.offsets = m_keys.offsets.data();
		keyEx.strpool = m_keys.strpool.data();
		size_t lo = lower_bound_ex_0(index, rows, key, keyEx, cmp);
		*pLower = lo;
		if (lo < rows) {
			size_t jj = m_ids[lo];
			if (key == m_keys[jj])
				return 0;
			else
				return 1;
		}
	}
	return -1;
}
コード例 #23
0
ファイル: FUStringConversion.cpp プロジェクト: righnatios/0ad
// Split a fstring into multiple substrings
void FUStringConversion::ToFStringList(const fstring& value, FStringList& array)
{
	const fchar* s = value.c_str();

	// Skip beginning white spaces
	fchar c;
	while ((c = *s) != 0 && (c == ' ' || c == '\t' || c == '\r' || c == '\n')) { ++s; }

	size_t index = 0;
	while (*s != 0)
	{
		const fchar* word = s;

		// Find next white space
		while ((c = *s) != 0 && c != ' ' && c != '\t' && c != '\r' && c != '\n') { ++s; }

		if (index < array.size()) array[index++].append(word, s - word);
		else { array.push_back(fstring(word, s - word)); ++index; }

		// Skip all white spaces
		while ((c = *s) != 0 && (c == ' ' || c == '\t' || c == '\r' || c == '\n')) { ++s; }
	}
	array.resize(index);
}
コード例 #24
0
ファイル: ptree.cpp プロジェクト: GreatStone/terark-db
	bool operator()(fstring name, obj** x) const {
		if (path.end() == name.end() && NULL == *x) {
			*x = new typename obj_val<Obj>::type(val);
		}
		return true;
	}
コード例 #25
0
BadChecksumException::
BadChecksumException(fstring msg, uint64_t Old, uint64_t New)
  : super(msg.c_str()), m_old(Old), m_new(New) {}
コード例 #26
0
void FCDEntityInstance::SetName(const fstring& _name) 
{
	name = FCDEntity::CleanName(_name.c_str());
	SetDirtyFlag();
}
コード例 #27
0
void DFA_Interface::save_to(fstring fname) const {
	assert('\0' == *fname.end());
	febird::FileStream file(fname.p, "wb");
	save_to(file);
}