예제 #1
0
/// Allocate specified number of components if necessary
size_t CGPUProgramParams::allocOffset(const std::string &name, uint size, uint count, TType type)
{
	nlassert(count > 0); // this code will not properly handle 0
	nlassert(size > 0); // this code will not properly handle 0
	nlassert(!name.empty()); // sanity check

	uint nbComponents = size * count;
	size_t offset = getOffset(name);
	if (offset != s_End)
	{
		if (getCountByOffset(offset) >= nbComponents)
		{
			m_Meta[offset].Type = type;
			m_Meta[offset].Size = size;
			m_Meta[offset].Count = count;
			return offset;
		}
		if (getCountByOffset(offset) < nbComponents)
		{
			freeOffset(offset);
		}
	}

	// Allocate space
	offset = allocOffset(size, count, type);

	// Fill
	m_Meta[offset].Name = name;

	// Store offset in map
	m_MapName[name] = offset;

	return offset;
}
예제 #2
0
void CGPUProgramParams::map(uint index, const std::string &name)
{
	size_t offsetIndex = getOffset(index);
	size_t offsetName = getOffset(name);
	if (offsetName != getEnd())
	{
		// Remove possible duplicate
		if (offsetIndex != getEnd())
		{
			freeOffset(offsetIndex);
		}

		// Set index
		m_Meta[offsetName].Index = index;

		// Map index to name
		if (index >= m_Map.size())
			m_Map.resize(index + 1, s_End);
		m_Map[index] = offsetName;
	}
	else if (offsetIndex != getEnd())
	{
		// Set name
		m_Meta[offsetIndex].Name = name;

		// Map name to index
		m_MapName[name] = offsetIndex;
	}
}
예제 #3
0
void CGPUProgramParams::unset(const std::string &name)
{
	size_t offset = getOffset(name);
	if (offset != getEnd())
	{
		freeOffset(offset);
	}
}
예제 #4
0
void CGPUProgramParams::unset(uint index)
{
	size_t offset = getOffset(index);
	if (offset != getEnd())
	{
		freeOffset(offset);
	}
}
예제 #5
0
파일: Page.cpp 프로젝트: apir8181/hash
//add a record, if success return 1, else 0
bool Page::addRecord(char* rec){

    if ( canAddRecord(rec) ){

        int temp = getSlotNumber();
        int free_off =  freeOffset();
        int rec_length = strlen( rec );

		//copy the record into the page and update related data
		memcpy( content + free_off, rec, sizeof( char ) * rec_length );
        setRecordLength( temp, rec_length );
        setRecordOffset( temp, free_off );

		//update the free offset and number of the slot in the page
        setFreeOffset( free_off + rec_length );
        slotNumberAdd();

        return 1;
    }
    else return 0;

}
예제 #6
0
/// Allocate specified number of components if necessary
size_t CGPUProgramParams::allocOffset(uint index, uint size, uint count, TType type)
{
	nlassert(count > 0); // this code will not properly handle 0
	nlassert(size > 0); // this code will not properly handle 0
	nlassert(index < 0xFFFF); // sanity check

	uint nbComponents = size * count;
	size_t offset = getOffset(index);
	if (offset != s_End)
	{
		if (getCountByOffset(offset) >= nbComponents)
		{
			m_Meta[offset].Type = type;
			m_Meta[offset].Size = size;
			m_Meta[offset].Count = count;
			return offset;
		}
		if (getCountByOffset(offset) < nbComponents)
		{
			freeOffset(offset);
		}
	}

	// Allocate space
	offset = allocOffset(size, count, type);

	// Fill
	m_Meta[offset].Index = index;

	// Store offset in map
	if (index >= m_Map.size())
		m_Map.resize(index + 1, s_End);
	m_Map[index] = offset;

	return offset;
}
예제 #7
0
파일: Page.cpp 프로젝트: apir8181/hash
//if can add record return 1,else 0
bool Page::canAddRecord( char *rec ){
    if ( freeOffset() + strlen(rec) + 8 + 8 * getSlotNumber() + 8 < CAPACITY ) return 1;
	else return 0;
}