1
0
Fork 0

Merge branch 'oreste' of github.com:triAGENS/AvocadoDB

Conflicts:
	BasicsC/vector.c
This commit is contained in:
Frank Celler 2012-05-08 09:31:26 +02:00
commit db868d1147
8 changed files with 130 additions and 16 deletions

View File

@ -240,6 +240,57 @@ void* TRI_AtVector (TRI_vector_t const* vector, size_t pos) {
return (void*) (vector->_buffer + pos * vector->_elementSize);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief inserts an element at a given position
////////////////////////////////////////////////////////////////////////////////
void TRI_InsertVector (TRI_vector_t* vector, void const* element, size_t position) {
char* newBuffer;
size_t newSize;
// ...........................................................................
// Check and see if we need to extend the vector
// ...........................................................................
if (vector->_length >= vector->_capacity || position >= vector->_length) {
newSize = (size_t) (1 + GROW_FACTOR * vector->_capacity);
if (position >= newSize) {
newSize = position + 1;
}
newBuffer = (char*) TRI_Allocate(newSize * vector->_elementSize);
if (newBuffer == NULL) {
TRI_set_errno(TRI_ERROR_OUT_OF_MEMORY);
return;
}
vector->_capacity = newSize;
if (vector->_buffer != NULL) {
memcpy(newBuffer, vector->_buffer, vector->_length * vector->_elementSize);
TRI_Free(vector->_buffer);
}
vector->_buffer = newBuffer;
}
if (position < vector->_length) {
memmove(vector->_buffer + (vector->_elementSize * (position + 1)),
vector->_buffer + (vector->_elementSize * position),
vector->_elementSize * (vector->_length - position)
);
vector->_length += 1;
}
else {
vector->_length = position + 1;
}
memcpy(vector->_buffer + (vector->_elementSize * position), element, vector->_elementSize);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief sets an element at a given position
////////////////////////////////////////////////////////////////////////////////
@ -458,6 +509,11 @@ int TRI_PushBackVectorPointer (TRI_vector_pointer_t* vector, void* element) {
////////////////////////////////////////////////////////////////////////////////
int TRI_InsertVectorPointer (TRI_vector_pointer_t* vector, void* element, size_t n) {
// ...........................................................................
// Check and see if we need to extend the vector
// ...........................................................................
if (vector->_length >= vector->_capacity || n >= vector->_length) {
void* newBuffer;
size_t newSize = (size_t) (1 + GROW_FACTOR * vector->_capacity);
@ -729,6 +785,12 @@ int TRI_PushBackVectorString (TRI_vector_string_t* vector, char* element) {
int TRI_InsertVectorString (TRI_vector_string_t* vector, char* element, size_t n) {
if (n >= vector->_capacity || n >= vector->_length) {
// ...........................................................................
// Check and see if we need to extend the vector
// ...........................................................................
if (n >= vector->_capacity) {
char** newBuffer;
size_t newSize = (size_t) (1 + GROW_FACTOR * vector->_capacity);

View File

@ -146,6 +146,13 @@ void TRI_RemoveVector (TRI_vector_t*, size_t n);
void* TRI_AtVector (TRI_vector_t const*, size_t);
////////////////////////////////////////////////////////////////////////////////
/// @brief inserts an element at a given position
////////////////////////////////////////////////////////////////////////////////
void TRI_InsertVector (TRI_vector_t* vector, void const* element, size_t position);
////////////////////////////////////////////////////////////////////////////////
/// @brief sets an element at a given position
////////////////////////////////////////////////////////////////////////////////

View File

@ -74,6 +74,8 @@ typedef struct array_shaper_s {
TRI_associative_pointer_t _shapeDictionary;
TRI_vector_pointer_t _shapes;
// todo: add attribute weight structure
}
array_shaper_t;
@ -402,6 +404,12 @@ static char const* LookupAttributeIdArrayShaper (TRI_shaper_t* shaper, TRI_shape
return NULL;
}
static int64_t LookupAttributeWeight (TRI_shaper_t* shaper, TRI_shape_aid_t aid) {
// todo: add support for an attribute weight
assert(0);
return -1;
}
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
@ -559,7 +567,8 @@ TRI_shaper_t* TRI_CreateArrayShaper (TRI_memory_zone_t* zone) {
shaper->base.lookupAttributeId = LookupAttributeIdArrayShaper;
shaper->base.findShape = FindShapeShape;
shaper->base.lookupShapeId = LookupShapeId;
shaper->base.lookupAttributeWeight = LookupAttributeWeight;
// handle basics
ok = TRI_InsertBasicTypesShaper(&shaper->base);

View File

@ -60,7 +60,7 @@ typedef struct TRI_shaper_s {
char const* (*lookupAttributeId) (struct TRI_shaper_s*, TRI_shape_aid_t);
TRI_shape_t const* (*findShape) (struct TRI_shaper_s*, TRI_shape_t*);
TRI_shape_t const* (*lookupShapeId) (struct TRI_shaper_s*, TRI_shape_sid_t);
int64_t (*lookupAttributeWeight) (struct TRI_shaper_s*, TRI_shape_aid_t);
TRI_shape_path_t const* (*lookupAttributePathByPid) (struct TRI_shaper_s*, TRI_shape_pid_t);
TRI_shape_pid_t (*findAttributePathByName) (struct TRI_shaper_s*, char const*);

View File

@ -469,7 +469,22 @@ static int CompareShapedJsonShapedJson (const TRI_shaped_json_t* left, const TRI
}
result = CompareShapeTypes (left, right, leftShaper, rightShaper);
// ............................................................................
// In the above function CompareShaeTypes we use strcmp which may return
// an integer greater than 1 or less than -1. From this function we only
// need to know whether we have equality (0), less than (-1) or greater than (1)
// ............................................................................
if (result < 0) {
result = -1;
}
else if (result > 0) {
result = 1;
}
return result;
} // end of function CompareShapedJsonShapedJson
@ -718,7 +733,16 @@ static int IndexStaticMultiCompareElementElement (TRI_skiplist_multi_t* multiSki
for (j = 0; j < hLeftElement->numFields; j++) {
compareResult = CompareShapedJsonShapedJson((j + hLeftElement->fields), (j + hRightElement->fields), leftShaper, rightShaper);
if (compareResult != 0) {
// ......................................................................
// The function CompareShaedJsonShapedJson can only return 0, -1, or 1
// that is, TRI_SKIPLIST_COMPARE_STRICTLY_EQUAL (0)
// TRI_SKIPLIST_COMPARE_STRICTLY_LESS (-1)
// TRI_SKIPLIST_COMPARE_STRICTLY_GREATER (1)
// ......................................................................
return compareResult;
}
}

View File

@ -25,9 +25,10 @@
/// @author Copyright 2006-2012, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
#include "skiplist.h"
#include <BasicsC/logging.h>
#include <BasicsC/random.h>
#include "skiplist.h"
#include "compare.h"
#define SKIPLIST_ABSOLUTE_MAX_HEIGHT 100
@ -340,11 +341,11 @@ void TRI_InitSkipList (TRI_skiplist_t* skiplist, size_t elementSize,
}
// ..........................................................................
// Assign the comparision call back functions
// Assign the STATIC comparision call back functions
// ..........................................................................
skiplist->compareElementElement = compareElementElement;
skiplist->compareKeyElement = compareKeyElement;
skiplist->compareElementElement = IndexStaticCompareElementElement; // compareElementElement;
skiplist->compareKeyElement = IndexStaticCompareKeyElement; // compareKeyElement;
// ..........................................................................
// Assign the maximum height of the skip list. This maximum height must be
@ -352,7 +353,7 @@ void TRI_InitSkipList (TRI_skiplist_t* skiplist, size_t elementSize,
// ..........................................................................
skiplist->_base._maxHeight = maximumHeight;
if (maximumHeight > SKIPLIST_ABSOLUTE_MAX_HEIGHT) {
printf("%s:%d:Invalid maximum height for skiplist\n",__FILE__,__LINE__);
LOG_ERROR("Invalid maximum height for skiplist", TRI_ERROR_INTERNAL);
assert(false);
}
@ -1290,7 +1291,7 @@ void* TRI_RightLookupByKeySkipList (TRI_skiplist_t* skiplist, void* key) {
// Use the callback to determine if the element is less or greater than
// the next node element.
// .......................................................................
compareResult = IndexStaticCompareKeyElement(skiplist,key,&(prevNode->_element), 1);
compareResult = IndexStaticCompareKeyElement(skiplist, key, &(prevNode->_element), 1);
// .......................................................................
@ -1311,7 +1312,7 @@ void* TRI_RightLookupByKeySkipList (TRI_skiplist_t* skiplist, void* key) {
}
// .......................................................................
// The element is greater than the next node element. Keep going on this
// The key is greater than the next node element. Keep going on this
// level.
// .......................................................................
if (compareResult < 0) {
@ -1399,9 +1400,9 @@ void TRI_InitSkipListMulti (TRI_skiplist_multi_t* skiplist,
// Assign the comparision call back functions
// ..........................................................................
skiplist->compareElementElement = compareElementElement;
skiplist->compareKeyElement = compareKeyElement;
skiplist->equalElementElement = equalElementElement;
skiplist->compareElementElement = IndexStaticMultiCompareElementElement; //compareElementElement;
skiplist->compareKeyElement = IndexStaticMultiCompareKeyElement; // compareKeyElement;
skiplist->equalElementElement = IndexStaticMultiEqualElementElement; //equalElementElement;
// ..........................................................................
// Assign the maximum height of the skip list. This maximum height must be
@ -1409,7 +1410,7 @@ void TRI_InitSkipListMulti (TRI_skiplist_multi_t* skiplist,
// ..........................................................................
skiplist->_base._maxHeight = maximumHeight;
if (maximumHeight > SKIPLIST_ABSOLUTE_MAX_HEIGHT) {
printf("%s:%d:Invalid maximum height for skiplist\n",__FILE__,__LINE__);
LOG_ERROR("Invalid maximum height for skiplist", TRI_ERROR_INTERNAL);
assert(false);
}
@ -2114,7 +2115,7 @@ int TRI_RemoveElementSkipListMulti (TRI_skiplist_multi_t* skiplist, void* elemen
}
// .....................................................................
// The element could be located and we are at the lowest level
// The element could be located (by matching the key) and we are at the lowest level
// .....................................................................
if (compareResult == TRI_SKIPLIST_COMPARE_SLIGHTLY_LESS) {
goto END;
@ -2163,7 +2164,7 @@ int TRI_RemoveElementSkipListMulti (TRI_skiplist_multi_t* skiplist, void* elemen
// ..........................................................................
if (old != NULL) {
memcpy(old, &(currentNode->_element), skiplist->_base._elementSize);
IndexStaticCopyElementElement(&(skiplist->_base), old, &(currentNode->_element));
}

View File

@ -1150,6 +1150,8 @@ static bool multiSkiplistIndex_findHelperIntervalValid(SkiplistIndex* skiplistIn
compareResult = skiplistIndex->skiplist.nonUniqueSkiplist->compareKeyElement(
skiplistIndex->skiplist.nonUniqueSkiplist,
&(lNode->_element), &(rNode->_element), 0);
return (compareResult == -1);
}
@ -1292,6 +1294,7 @@ TRI_skiplist_iterator_t* MultiSkiplistIndex_find(SkiplistIndex* skiplistIndex, T
if (results == NULL) {
return NULL;
}
results->_index = skiplistIndex;
TRI_InitVector(&(results->_intervals), TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_skiplist_iterator_interval_t));
results->_currentInterval = 0;

View File

@ -480,6 +480,14 @@ BOOST_AUTO_TEST_CASE (tst_insert) {
void* r = 0;
// ...........................................................................
// this test needs to be altered slightly e.g.
// TRI_InsertVectorPointer(&v1, &a, 100);
// TRI_InsertVectorPointer(&v1, &a, 20);
// TRI_InsertVectorPointer(&v1, &a, 200);
// ...........................................................................
TRI_InsertVectorPointer(&v1, &a, 0);
BOOST_CHECK_EQUAL((size_t) 1, v1._length);
BOOST_CHECK_EQUAL(&a, TRI_AtVectorPointer(&v1, 0));