Exemplo n.º 1
0
int PQIndex_remove(PQIndex* idx, PQIndexElement* element) {

  PQIndexElement* item;  
  bool ok;
  
  if (idx == NULL) {
    return TRI_ERROR_ARANGO_INDEX_PQ_REMOVE_FAILED;
  }

  if (element == NULL) {
    return TRI_ERROR_ARANGO_INDEX_PQ_REMOVE_FAILED;
  }
  
  // ...........................................................................
  // Check if item exists in the associative array.
  // ...........................................................................

  item = TRI_FindByKeyAssociativeArray(idx->_aa, element->data);
  if (item == NULL) {
    return TRI_ERROR_ARANGO_INDEX_PQ_REMOVE_ITEM_MISSING;
  }

  
  // ...........................................................................
  // Remove item from the priority queue
  // ...........................................................................
  
  ok = idx->_pq->remove(idx->_pq,item->pqSlot, true);

 
  // ...........................................................................
  // Remove item from associative array
  // Must come after remove above, since update storage will be called.
  // ...........................................................................
  
  ok = TRI_RemoveElementAssociativeArray(idx->_aa,item,NULL) && ok;
  
  if (!ok) {
    return TRI_ERROR_ARANGO_INDEX_PQ_REMOVE_FAILED;
  }
  
  return TRI_ERROR_NO_ERROR;  
}  
Exemplo n.º 2
0
int PQIndex_add(PQIndex* idx, PQIndexElement* element) {

  if (idx == NULL) {
    return TRI_ERROR_INTERNAL;
  }

  if (element == NULL) {
    return TRI_ERROR_INTERNAL;
  }
  
  // ...........................................................................
  // Check if item is already added to the associative array
  // ...........................................................................

  if (TRI_FindByKeyAssociativeArray(idx->_aa, element->data) != NULL) {
    // attempt to add duplicate document to the priority queue
    return TRI_ERROR_ARANGO_INDEX_PQ_INSERT_FAILED;
  }

  
  // ...........................................................................
  // Initialise the priority queue array storage pointer
  // ...........................................................................
  element->pqSlot = 0;
  
  // ...........................................................................
  // Add item to associative array
  // ...........................................................................
  if (!TRI_InsertElementAssociativeArray(idx->_aa, element, false)) {
    // can not add item to associative array -- give up on insert
    return TRI_ERROR_ARANGO_INDEX_PQ_INSERT_FAILED;
  }

  
  if (!idx->_pq->add(idx->_pq, element)) {
    TRI_RemoveElementAssociativeArray(idx->_aa, element, NULL);
    // can not add item to priority queue array -- give up on insert
    return TRI_ERROR_ARANGO_INDEX_PQ_INSERT_FAILED;
  }
  
  return TRI_ERROR_NO_ERROR;
}
Exemplo n.º 3
0
int TRI_RemoveElementBitarray (TRI_bitarray_t* ba, TRI_doc_mptr_t* element) {
  TRI_master_table_position_t* position;
  TRI_bitarray_mask_t mask;
  MasterTable_t* mt;
  MasterTableBlock_t* block;
  int result;
  bool ok;

  // ..........................................................................
  // Attempt to locate the position of the element within the Master Block table
  // ..........................................................................

  mt = (MasterTable_t*)(ba->_masterTable);
  position = (TRI_master_table_position_t*)(TRI_FindByKeyAssociativeArray(&(mt->_tablePosition),element));

  if (position == NULL) {
    return TRI_ERROR_ARANGO_INDEX_BITARRAY_REMOVE_ITEM_MISSING;
  }

  // ..........................................................................
  // Observe that we are NOT removing any entries from the actual bit arrays.
  // All we are 'removing' are entries in the master block table.
  // ..........................................................................

  result = removeElementMasterTable(mt, position);

  // ...........................................................................
  // It may happen that the block is completely free, moreover it may happen
  // that we are fortunate and it is the last used block.
  // ...........................................................................

  block = &(mt->_blocks[position->_blockNum]);

  // TODO: comparison is always false due to limited range of data type [-Wtype-limits]
  if (block->_free == BITARRAY_COLUMN_FREE_MARKER) {
    if (ba->_lastBlockUsed == position->_blockNum) {
      --ba->_lastBlockUsed;
    }
  }

  if (result != TRI_ERROR_NO_ERROR) {
    return result;
  }

  mask._mask = 0;
  mask._ignoreMask = 0;
  setBitarrayMask(ba, &mask, position);


  // ..........................................................................
  // Remove the entry from associative array
  // ..........................................................................

  ok = TRI_RemoveKeyAssociativeArray(&(mt->_tablePosition), element, NULL);

  if (!ok) {
    return TRI_ERROR_INTERNAL;
  }

  // debugPrintBitarray(ba);
  return TRI_ERROR_NO_ERROR;
}
Exemplo n.º 4
0
int TRI_InsertBitMaskElementBitarray (TRI_bitarray_t* ba,
                                      TRI_bitarray_mask_t* mask,
                                      TRI_doc_mptr_t* element) {
  MasterTable_t* mt;
  TRI_master_table_position_t position;
  int result;

  if (ba == NULL || mask == NULL || element == NULL) {
    return TRI_ERROR_INTERNAL;
  }

  mt = (MasterTable_t*)(ba->_masterTable);

  if (mt == NULL) {
    return TRI_ERROR_INTERNAL;
  }

  // ..........................................................................
  // Ensure that the element we are going to insert into the MasterBlockTable
  // and the bitarrays is not already there.
  // ..........................................................................

  if (TRI_FindByKeyAssociativeArray(&(mt->_tablePosition),element) != NULL) {
    TRI_ASSERT(false);
    return TRI_ERROR_INTERNAL; // Todo: return correct error
  }

  // ..........................................................................
  // The insertion into the MasterBlockTable occurs first and has priority
  // ..........................................................................

  position._blockNum   = 0;
  position._bitNum     = 0;
  position._vectorNum  = 0;
  position._docPointer = element; // assign the document pointer
  result = insertMasterTable(mt, &position);

  if (result != TRI_ERROR_NO_ERROR) {
    return result;
  }

  // ...........................................................................
  // locate the position in the bitarrays, extend the bit arrays if necessary
  // ...........................................................................

  if (position._blockNum >= ba->_numBlocksInColumn) {
    result = extendColumns(ba, position._blockNum + 1);

    if (result != TRI_ERROR_NO_ERROR) {
      return result;
    }
  }

  // ...........................................................................
  // Use the mask to set the bits in each column to 0 or 1
  // ...........................................................................

  setBitarrayMask(ba, mask, &position);
  //debugPrintMask(ba,mask->_mask);

  // ...........................................................................
  // update the last block which is in use -- a small amount of help so that
  // we do not keep scanning indefinitely down the columns
  // ...........................................................................

  if (ba->_lastBlockUsed < position._blockNum) {
    ba->_lastBlockUsed = position._blockNum;
  }

  //debugPrintBitarray(ba);

  return TRI_ERROR_NO_ERROR;
}