Commit c28417c8 authored by biagio montesano's avatar biagio montesano

Array32 class removal.

parent 9a52f462
...@@ -888,51 +888,6 @@ protected: ...@@ -888,51 +888,6 @@ protected:
AlgorithmInfo* info() const; AlgorithmInfo* info() const;
private: private:
class Array32
{
public:
/* set ARRAY_RESIZE_FACTOR */
static void setArrayResizeFactor( double arf );
/* constructor */
Array32();
/* destructor */
~Array32();
/* cleaning function used in destructor */
void cleanup();
/* push data */
void push( UINT32 data );
/* insert data at given index */
void insert( UINT32 index, UINT32 data );
/* return data */
UINT32* data();
/* return data size */
UINT32 size();
/* return capacity */
UINT32 capacity();
/* definition of operator = */
void operator=( const Array32& );
/* print data */
void print();
/* initializer */
void init( int size );
/* data */
UINT32 *arr;
};
class BucketGroup class BucketGroup
{ {
...@@ -949,9 +904,14 @@ void insert( int subindex, UINT32 data ); ...@@ -949,9 +904,14 @@ void insert( int subindex, UINT32 data );
/* perform a query to the bucket */ /* perform a query to the bucket */
UINT32* query( int subindex, int *size ); UINT32* query( int subindex, int *size );
/* utility functions */
void insert_value( std::vector<uint32_t>& vec, int index, UINT32 data );
void push_value( std::vector<uint32_t>& vec, UINT32 Data );
/* data fields */ /* data fields */
UINT32 empty; UINT32 empty;
Array32 *group; std::vector<uint32_t> group;
}; };
......
...@@ -844,7 +844,7 @@ int BinaryDescriptorMatcher::SparseHashtable::init( int _b ) ...@@ -844,7 +844,7 @@ int BinaryDescriptorMatcher::SparseHashtable::init( int _b )
/* destructor */ /* destructor */
BinaryDescriptorMatcher::SparseHashtable::~SparseHashtable() BinaryDescriptorMatcher::SparseHashtable::~SparseHashtable()
{ {
free( table ); free (table);
} }
/* insert data */ /* insert data */
...@@ -863,205 +863,109 @@ UINT32* BinaryDescriptorMatcher::SparseHashtable::query( UINT64 index, int *Size ...@@ -863,205 +863,109 @@ UINT32* BinaryDescriptorMatcher::SparseHashtable::query( UINT64 index, int *Size
BinaryDescriptorMatcher::BucketGroup::BucketGroup() BinaryDescriptorMatcher::BucketGroup::BucketGroup()
{ {
empty = 0; empty = 0;
group = NULL; group = std::vector < uint32_t > ( 2, 0 );
} }
/* destructor */ /* destructor */
BinaryDescriptorMatcher::BucketGroup::~BucketGroup() BinaryDescriptorMatcher::BucketGroup::~BucketGroup()
{ {
if( group != NULL )
delete group;
} }
/* insert data into the bucket */ void BinaryDescriptorMatcher::BucketGroup::insert_value( std::vector<uint32_t>& vec, int index, UINT32 data )
void BinaryDescriptorMatcher::BucketGroup::insert( int subindex, UINT32 data )
{ {
if( group == NULL ) if( vec.size() > 1 )
{
group = new Array32();
group->push( 0 );
}
UINT32 lowerbits = ( (UINT32) 1 << subindex ) - 1;
int end = popcnt( empty & lowerbits );
if( ! ( empty & ( (UINT32) 1 << subindex ) ) )
{ {
group->insert( end, group->arr[end + 2] ); if( vec[0] == vec[1] )
empty |= (UINT32) 1 << subindex; {
} vec[1] = (UINT32) ceil( vec[0] * 1.1 );
for ( int i = 0; i < (int) ( 2 + vec[1] - vec.size() ); i++ )
vec.push_back( 0 );
int totones = popcnt( empty ); }
group->insert( totones + 1 + group->arr[2 + end + 1], data );
for ( int i = end + 1; i < totones + 1; i++ )
group->arr[2 + i]++;
}
/* perform a query to the bucket */ vec.insert( vec.begin() + 2 + index, data );
UINT32* BinaryDescriptorMatcher::BucketGroup::query( int subindex, int *size ) vec[2 + index] = data;
{ vec[0]++;
if( empty & ( (UINT32) 1 << subindex ) )
{
UINT32 lowerbits = ( (UINT32) 1 << subindex ) - 1;
int end = popcnt( empty & lowerbits );
int totones = popcnt( empty );
*size = group->arr[2 + end + 1] - group->arr[2 + end];
return group->arr + 2 + totones + 1 + group->arr[2 + end];
} }
else else
{ {
*size = 0; vec = std::vector < uint32_t > ( 3, 0 );
return NULL; vec[0] = 1;
vec[1] = 1;
vec[2] = data;
} }
} }
/* set ARRAY_RESIZE_FACTOR */ void BinaryDescriptorMatcher::BucketGroup::push_value( std::vector<uint32_t>& vec, UINT32 Data )
void BinaryDescriptorMatcher::Array32::setArrayResizeFactor( double arf )
{
ARRAY_RESIZE_FACTOR = arf;
}
/* constructor */
BinaryDescriptorMatcher::Array32::Array32()
{
arr = NULL;
ARRAY_RESIZE_FACTOR = 1.1; // minimum is 1.0
ARRAY_RESIZE_ADD_FACTOR = 4; // minimum is 1
}
/* definition of operator =
Array32& Array32::operator = (const Array32 &rhs) */
void BinaryDescriptorMatcher::Array32::operator =( const Array32 &rhs )
{ {
if( &rhs != this ) if( vec.size() > 0 )
this->arr = rhs.arr;
}
/* destructor */
BinaryDescriptorMatcher::Array32::~Array32()
{
cleanup();
}
/* cleaning function used in destructor */
void BinaryDescriptorMatcher::Array32::cleanup()
{
free( arr );
}
/* push data */
void BinaryDescriptorMatcher::Array32::push( UINT32 Data )
{
if( arr )
{ {
if( arr[0] == arr[1] ) if( vec[0] == vec[1] )
{ {
arr[1] = (UINT32) std::max( ceil( arr[1] * ARRAY_RESIZE_FACTOR ), arr[1] + ARRAY_RESIZE_ADD_FACTOR ); vec[1] = (UINT32) std::max( ceil( vec[1] * ARRAY_RESIZE_FACTOR ), vec[1] + ARRAY_RESIZE_ADD_FACTOR );
UINT32* new_Data = static_cast<UINT32*>( realloc( arr, sizeof(UINT32) * ( 2 + arr[1] ) ) ); for ( int i = 0; i < (int) ( 2 + vec[1] - vec.size() ); i++ )
if( new_Data == NULL ) vec.push_back( 0 );
{
/* could not realloc, but orig still valid */
std::cout << "ALERT!!!! Not enough memory, operation aborted!" << std::endl;
exit( 0 );
}
else
{
arr = new_Data;
}
} }
arr[2 + arr[0]] = Data; vec[2 + vec[0]] = Data;
arr[0]++; vec[0]++;
} }
else else
{ {
arr = (UINT32*) malloc( ( size_t )( 2 + ARRAY_RESIZE_ADD_FACTOR ) * sizeof(UINT32) ); vec = std::vector < uint32_t > ( 2 + ARRAY_RESIZE_ADD_FACTOR, 0 );
arr[0] = 1; vec[0] = 1;
arr[1] = 1; vec[1] = 1;
arr[2] = Data; vec[2] = Data;
} }
} }
/* insert data at given index */ /* insert data into the bucket */
void BinaryDescriptorMatcher::Array32::insert( UINT32 index, UINT32 Data ) void BinaryDescriptorMatcher::BucketGroup::insert( int subindex, UINT32 data )
{ {
if( arr ) if( group.size() == 0 )
{ {
if( arr[0] == arr[1] ) push_value( group, 0 );
{
arr[1] = (UINT32) ceil( arr[0] * 1.1 );
UINT32* new_data = static_cast<UINT32*>( realloc( arr, sizeof(UINT32) * ( 2 + arr[1] ) ) );
if( new_data == NULL )
{
// could not realloc, but orig still valid
std::cout << "ALERT!!!! Not enough memory, operation aborted!" << std::endl;
exit( 0 );
}
else
{
arr = new_data;
}
}
memmove( arr + ( 2 + index ) + 1, arr + ( 2 + index ), ( arr[0] - index ) * sizeof ( *arr ) );
arr[2 + index] = Data;
arr[0]++;
} }
else UINT32 lowerbits = ( (UINT32) 1 << subindex ) - 1;
int end = popcnt( empty & lowerbits );
if( ! ( empty & ( (UINT32) 1 << subindex ) ) )
{ {
arr = (UINT32*) malloc( 3 * sizeof(UINT32) ); insert_value( group, end, group[end + 2] );
arr[0] = 1; empty |= (UINT32) 1 << subindex;
arr[1] = 1;
arr[2] = Data;
} }
}
/* return data */ int totones = popcnt( empty );
UINT32* BinaryDescriptorMatcher::Array32::data() insert_value( group, totones + 1 + group[2 + end + 1], data );
{
return arr ? arr + 2 : NULL;
}
/* return data size */
UINT32 BinaryDescriptorMatcher::Array32::size()
{
return arr ? arr[0] : 0;
}
/* return capacity */ for ( int i = end + 1; i < totones + 1; i++ )
UINT32 BinaryDescriptorMatcher::Array32::capacity() group[2 + i]++;
{
return arr ? arr[1] : 0;
} }
/* print data */ /* perform a query to the bucket */
void BinaryDescriptorMatcher::Array32::print() UINT32* BinaryDescriptorMatcher::BucketGroup::query( int subindex, int *size )
{ {
for ( int i = 0; i < (int) size(); i++ ) if( empty & ( (UINT32) 1 << subindex ) )
printf( "%d, ", arr[i + 2] ); {
UINT32 lowerbits = ( (UINT32) 1 << subindex ) - 1;
int end = popcnt( empty & lowerbits );
int totones = popcnt( empty );
printf( "\n" ); *size = group[2 + end + 1] - group[2 + end];
} return & ( * ( group.begin() + 2 + totones + 1 + (int) group[2 + end] ) );
}
/* initializer */ else
void BinaryDescriptorMatcher::Array32::init( int Size )
{
if( arr == NULL )
{ {
arr = (UINT32*) malloc( ( 2 + Size ) * sizeof(UINT32) ); *size = 0;
arr[0] = 0; return NULL;
arr[1] = Size;
} }
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment