Ejemplo n.º 1
0
void cache_object_init(struct cache_object *co)
{
    cache_index_init(&co->ci);
    cache_init(&co->cc);
    open_index_file(&co->ci);
    read_cache_index_file(&co->ci);
    open_cache_file(&co->cc);
    read_cache_file(&co->cc);
}
Ejemplo n.º 2
0
	bool bin_index_t::file_node::first(data_t& key,data_t& val) const
	{
		open_index_file();

		index_t ind;
		if(!first_item(root_page,ind))return false;

		key=ind.key;
		key.resize(key_len);
		val.resize(ind.data_len);
		load_data(ind.data_offset,val);
		return true;
	}
Ejemplo n.º 3
0
	bool bin_index_t::file_node::get(const data_t& key,data_t& val) const
	{
		validate_key_len(key);
		open_index_file();

		if(!root_page)
			return false;
		
		index_t ind;
		align_key(key,ind);

		if(!get_item(ind))return false;

		val.resize(ind.data_len);
		load_data(ind.data_offset,val);
		return true;
	}
Ejemplo n.º 4
0
	bool bin_index_t::file_node::set(const data_t& key,const data_t& val)
	{
		validate_key_len(key);
		open_index_file();

		if(!root_page)
		{
			root_page=create_page();
			append_page(*root_page);
			save_index_data(0,root_page->page_offset);
			add_page(root_page);
		}
		
		index_t it;
		align_key(key,it);

		if(get_item(it))
		{
			index_t old_i=it;

			if(it.data_len>=val.size())save_data(it.data_offset,val);
			else it.data_offset=append_data(val);
			it.data_len=val.size();

			if(old_i.data_offset==it.data_offset&&
				old_i.data_len==it.data_len)
				return false;

			update_page(it);
			return false;
		}

		index_t v;
		v.key=key;
		align_key(key,v);
		v.data_len=val.size();
		v.data_offset=append_data(val);

		add_item(v);

		return true;
	}