Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various small fixes from Asana #115

Merged
merged 1 commit into from
Jul 11, 2013
Merged
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
9 changes: 0 additions & 9 deletions src/tightdb/array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1158,15 +1158,6 @@ size_t Array::count(int64_t value) const
return count;
}


void Array::FindAllHamming(Array& result, uint64_t value, size_t maxdist, size_t offset) const
{
(void)result;
(void)value;
(void)maxdist;
(void)offset;
}

size_t Array::GetByteSize(bool align) const
{
size_t len = CalcByteLen(m_len, m_width);
Expand Down
1 change: 0 additions & 1 deletion src/tightdb/array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ class Array: public ArrayParent {
void Preset(int64_t min, int64_t max, size_t count);
void Preset(size_t bitwidth, size_t count);

void FindAllHamming(Array& result, uint64_t value, size_t maxdist, size_t offset=0) const;
int64_t sum(size_t start = 0, size_t end = (size_t)-1) const;
size_t count(int64_t value) const;
bool maximum(int64_t& result, size_t start = 0, size_t end = (size_t)-1) const;
Expand Down
19 changes: 0 additions & 19 deletions src/tightdb/column.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -673,25 +673,6 @@ void Column::LeafFindAll(Array &result, int64_t value, size_t add_offset, size_t
m_array->find_all(result, value, add_offset, start, end);
}

void Column::find_all_hamming(Array& result, uint64_t value, size_t maxdist, size_t offset) const
{
if (!IsNode()) {
m_array->FindAllHamming(result, value, maxdist, offset);
}
else {
// Get subnode table
const Array offsets = NodeGetOffsets();
const Array refs = NodeGetRefs();
const size_t count = refs.size();

for (size_t i = 0; i < count; ++i) {
const Column col(refs.GetAsRef(i));
col.find_all_hamming(result, value, maxdist, offset);
offset += offsets.GetAsSizeT(i);
}
}
}

size_t Column::find_pos(int64_t target) const TIGHTDB_NOEXCEPT
{
// NOTE: Binary search only works if the column is sorted
Expand Down
5 changes: 0 additions & 5 deletions src/tightdb/column.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,20 +177,15 @@ class Column : public ColumnBase {

void sort(size_t start, size_t end);
void ReferenceSort(size_t start, size_t end, Column &ref);

intptr_t GetPtr(size_t ndx) const {return intptr_t(get(ndx));} // FIXME: intptr_t is not guaranteed to exists, not even in C++11

void Clear() TIGHTDB_OVERRIDE;
void erase(size_t ndx) TIGHTDB_OVERRIDE;
void move_last_over(size_t ndx) TIGHTDB_OVERRIDE;
//void Resize(size_t len);

void Increment64(int64_t value, size_t start=0, size_t end=-1);
void IncrementIf(int64_t limit, int64_t value);

size_t find_first(int64_t value, size_t start=0, size_t end=-1) const;
void find_all(Array& result, int64_t value, size_t caller_offset=0, size_t start=0, size_t end=-1) const;
void find_all_hamming(Array& result, uint64_t value, size_t maxdist, size_t offset=0) const;
size_t find_pos(int64_t value) const TIGHTDB_NOEXCEPT;
size_t find_pos2(int64_t value) const TIGHTDB_NOEXCEPT;
bool find_sorted(int64_t target, size_t& pos) const TIGHTDB_NOEXCEPT;
Expand Down
133 changes: 0 additions & 133 deletions src/tightdb/column_basic_tpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,6 @@ void BasicColumn<T>::find_all(Array &result, T value, size_t start, size_t end)
TreeFindAll<T, BasicColumn<T> >(result, value, 0, start, end);
}


#if 1

template<typename T>
size_t BasicColumn<T>::count(T target) const
{
Expand Down Expand Up @@ -325,136 +322,6 @@ T BasicColumn<T>::maximum(size_t start, size_t end) const
return ColumnBase::aggregate<T, T, act_Max, None>(0, start, end, NULL);
}

/*
template<typename T>
void BasicColumn<T>::sort(size_t start, size_t end)
{
// TODO
assert(0);
}
*/

#else

// Alternative 'naive' reference implementation - useful for reference performance testing.
// TODO: test performance of column aggregates

template<typename T>
size_t BasicColumn<T>::count(T target) const
{
size_t count = 0;

if (m_array->IsNode()) {
const Array refs = NodeGetRefs();
const size_t n = refs.size();

for (size_t i = 0; i < n; ++i) {
const size_t ref = refs.GetAsRef(i);
const BasicColumn<T> col(ref, NULL, 0, m_array->GetAllocator());

count += col.count(target);
}
}
else {
count += ((BasicArray<T>*)m_array)->count(target);
}
return count;
}

template<typename T>
T BasicColumn<T>::sum(size_t start, size_t end) const
{
if (end == size_t(-1))
end = Size();

double sum = 0;

if (m_array->IsNode()) {
const Array refs = NodeGetRefs();
const size_t n = refs.size();

for (size_t i = start; i < n; ++i) {
const size_t ref = refs.GetAsRef(i);
const BasicColumn<T> col(ref, NULL, 0, m_array->GetAllocator());

sum += col.sum(start, end);
}
}
else {
sum += ((BasicArray<T>*)m_array)->sum(start, end);
}
return sum;
}

template<typename T>
double BasicColumn<T>::average(size_t start, size_t end) const
{
if (end == size_t(-1))
end = Size();
size_t size = end - start;
double sum2 = sum(start, end);
double avg = sum2 / double( size == 0 ? 1 : size );
return avg;
}

// #include <iostream>

template<typename T>
T BasicColumn<T>::minimum(size_t start, size_t end) const
{
if (end == size_t(-1))
end = Size();

T min_val = T(987.0);
if (m_array->IsNode()) {
const Array refs = NodeGetRefs();
const size_t n = refs.size();

for (size_t i = start; i < n; ++i) {
const size_t ref = refs.GetAsRef(i);
const BasicColumn<T> col(ref, NULL, 0, m_array->GetAllocator());
T val = col.minimum(start, end);
if (val < min_val || i == start) {
//std::cout << "Min " << i << ": " << min_val << " new val: " << val << "\n";
val = min_val;
}
}
}
else {
// std::cout << "array-min before: " << min_val;
((BasicArray<T>*)m_array)->minimum(min_val, start, end);
// std::cout << " after: " << min_val << "\n";
}
return min_val;
}

template<typename T>
T BasicColumn<T>::maximum(size_t start, size_t end) const
{
if (end == size_t(-1))
end = Size();

T max_val = T(0.0);
if (m_array->IsNode()) {
const Array refs = NodeGetRefs();
const size_t n = refs.size();

for (size_t i = start; i < n; ++i) {
const size_t ref = refs.GetAsRef(i);
const BasicColumn<T> col(ref, NULL, 0, m_array->GetAllocator());
T val = col.maximum(start, end);
if (val > max_val || i == start)
val = max_val;
}
}
else {
((BasicArray<T>*)m_array)->maximum(max_val, start, end);
}
return max_val;
}

#endif // reference implementation of aggregates

} // namespace tightdb

#endif // TIGHTDB_COLUMN_BASIC_TPL_HPP
8 changes: 6 additions & 2 deletions src/tightdb/query_engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,12 @@ template<> struct ColumnTypeTraits<double> {
typedef double sum_type;
static const DataType id = type_Double;
};

template<> struct ColumnTypeTraits<Date> {
typedef Column column_type;
typedef Array array_type;
typedef int64_t sum_type;
static const DataType id = type_Int;
};
// Only purpose is to return 'double' if and only if source column (T) is float and you're doing a sum (A)
template<class T, Action A> struct ColumnTypeTraitsSum {
typedef T sum_type;
Expand Down Expand Up @@ -633,7 +638,6 @@ template <class TConditionValue, class TConditionFunction> class IntegerNode: pu
else if (TAction == act_Sum && col_id == type_Int)
ret = aggregate_local<act_Sum, int64_t, void>(st, start, end, local_limit, source_column, matchcount);
else if (TAction == act_Sum && col_id == type_Float)
// todo, fixme, see if we must let sum return a double even when summing a float coltype
ret = aggregate_local<act_Sum, float, void>(st, start, end, local_limit, source_column, matchcount);
else if (TAction == act_Sum && col_id == type_Double)
ret = aggregate_local<act_Sum, double, void>(st, start, end, local_limit, source_column, matchcount);
Expand Down
24 changes: 0 additions & 24 deletions src/tightdb/table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1852,30 +1852,6 @@ ConstTableView Table::find_all_binary(size_t, BinaryData) const
throw runtime_error("Not implemented");
}


TableView Table::find_all_hamming(size_t column_ndx, uint64_t value, size_t max)
{
TIGHTDB_ASSERT(column_ndx < m_columns.size());

const Column& column = GetColumn(column_ndx);

TableView tv(*this);
column.find_all_hamming(tv.get_ref_column(), value, max);
return move(tv);
}

ConstTableView Table::find_all_hamming(size_t column_ndx, uint64_t value, size_t max) const
{
TIGHTDB_ASSERT(column_ndx < m_columns.size());

const Column& column = GetColumn(column_ndx);

ConstTableView tv(*this);
column.find_all_hamming(tv.get_ref_column(), value, max);
return move(tv);
}


TableView Table::distinct(size_t column_ndx)
{
TIGHTDB_ASSERT(column_ndx < m_columns.size());
Expand Down
4 changes: 0 additions & 4 deletions src/tightdb/table.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,10 +477,6 @@ class Table {
/// new top array.
std::size_t clone(Allocator&) const;

// Experimental
TableView find_all_hamming(size_t column_ndx, uint64_t value, size_t max);
ConstTableView find_all_hamming(size_t column_ndx, uint64_t value, size_t max) const;

#ifdef TIGHTDB_ENABLE_REPLICATION
struct LocalTransactLog;
LocalTransactLog transact_log() TIGHTDB_NOEXCEPT;
Expand Down
10 changes: 10 additions & 0 deletions src/tightdb/table_accessors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,16 @@ class ColumnAccessor<Taboid, col_idx, Date>: public ColumnAccessorBase<Taboid, c
public:
explicit ColumnAccessor(Taboid* t) TIGHTDB_NOEXCEPT: Base(t) {}

Date maximum() const
{
return Base::m_table->get_impl()->maximum_date(col_idx);
}

Date minimum() const
{
return Base::m_table->get_impl()->minimum_date(col_idx);
}

std::size_t find_first(Date value) const
{
return Base::m_table->get_impl()->find_first_date(col_idx, value);
Expand Down
Loading