Skip to content
This repository was archived by the owner on Aug 12, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/libcql/cql_future_result.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace cql {

cql::cql_client_t* client;
cql::cql_stream_id_t stream;
boost::shared_ptr<cql::cql_result_t> result;
cql::cql_result_t* result;
cql::cql_error_t error;
};

Expand Down
6 changes: 6 additions & 0 deletions include/libcql/cql_result.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ namespace cql {
virtual bool
exists(const std::string& column) const = 0;

virtual bool
column_name(int i,
std::string& output_keyspace,
std::string& output_table,
std::string& output_column) const = 0;

virtual bool
column_class(int i,
std::string& output) const = 0;
Expand Down
7 changes: 7 additions & 0 deletions include/libcql/cql_vector_stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ namespace cql {

struct vector_stream_t : std::streambuf
{
vector_stream_t(cql::cql_byte_t* begin, cql::cql_byte_t* end)
{
char* start = reinterpret_cast<char*>(begin);
this->setg(start, start, start + (end - begin));
this->setp(start, start + (end - begin));
}

vector_stream_t(std::vector<cql::cql_byte_t>& vec)
{
char* start = reinterpret_cast<char*>(&vec[0]);
Expand Down
131 changes: 37 additions & 94 deletions include/libcql/internal/cql_callback_storage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,145 +21,88 @@

#include <stdlib.h>
#include <stdint.h>
#include <vector>
#include <new>

namespace cql {
// this template class stores up to 128 values no more
template<typename value_t>
class small_indexed_storage {
private:
template <typename _value_t>
class entry_t {
struct {
struct {
// -1 - there is no next free index
// -2 - flags that his one has been allocated (for checks and stuff)
int32_t index; // signed because might be -1
int32_t count; // doesn't matter never should be negative (see index restrictions)
} next_free;
_value_t value;
} e;

public:
_value_t&
value()
{
return e.value;
}

const _value_t&
value() const
{
return e.value;
}

int8_t
next_free_index() const
{
return e.next_free.index;
}

// not counting this (so 0 means there are no free blocks behind this one)
int8_t
next_free_cnt() const
{
return e.next_free.count;
}

// count does not include this (so 0 means there are no free blocks behind this one)
// you won't need to set cnt in any case except initial allocation
void
set_next_free(int32_t index,
int32_t cnt = 0)
{
e.next_free.index = index;
e.next_free.count = cnt;
}

void
set_value(const _value_t& val)
{
e.value = val;
}

bool
is_allocated()
{
return e.next_free.index == -2;
}

void
set_allocated()
{
e.next_free.index = -2;
}
template<typename t>
struct bucket {
t value;
int is_allocated;
};

typedef entry_t<value_t> array_entry_t;
array_entry_t* array;
int32_t next_free_index;
std::vector< bucket<value_t>* > array;
std::vector<int32_t> frees;
public:
explicit
small_indexed_storage(uint16_t size) :
next_free_index(0)
small_indexed_storage(int32_t size)
{
array = new array_entry_t[size];
array[0].set_next_free(-1, size-1);
array.reserve(size);
}

~small_indexed_storage()
{
delete [] array;
for(size_t i=0; i<array.size(); i++)
{
release(i);
free(array[i]);
}
}

int32_t
int8_t
allocate()
{
int32_t result;
if ( (result = next_free_index) >= 0) {
if (array[next_free_index].next_free_cnt() > 0) {
array[++next_free_index].set_next_free(array[result].next_free_index(), array[result].next_free_cnt()-1);
}
else {
next_free_index = array[next_free_index].next_free_index();
}
// mark it allocated
array[result].set_allocated();
if (frees.size()) {
int32_t ret = frees.back();
frees.pop_back();
return ret;
} else {
bucket<value_t>* ptr = (bucket<value_t>*)calloc(1, sizeof(bucket<value_t>));
array.push_back(ptr);
return array.size() - 1;
}

return result;
}

void
release(int32_t index)
{
array[index].set_next_free(next_free_index);
next_free_index = index;
if (array[index]->is_allocated) {
array[index]->value.release();
array[index]->value.~value_t();
array[index]->is_allocated = 0;
}
frees.push_back(index);
}

bool
has(int32_t index) const
{
return array[index].is_allocated();
return (int32_t)array.size() > index && array[index]->is_allocated;
}

value_t&
get(int32_t index)
{
return array[index].value();
return array[index]->value;
}

const value_t&
get(int32_t index) const
{
return array[index].value();
return array[index]->value;
}

void
put(int32_t index,
const value_t& val)
{
array[index].set_value(val);
if (array[index]->is_allocated) {
array[index]->value.~value_t();
}
array[index]->is_allocated = 1;
new (&array[index]->value) value_t(val);
}

};
Expand Down
Loading