示例#1
0
TRI_index_t* TRI_CreateCapConstraint (TRI_document_collection_t* document,
                                      TRI_idx_iid_t iid,
                                      size_t count,
                                      int64_t size) {
  TRI_cap_constraint_t* cap = static_cast<TRI_cap_constraint_t*>(TRI_Allocate(TRI_CORE_MEM_ZONE, sizeof(TRI_cap_constraint_t), false));

  if (cap == nullptr) {
    return nullptr;
  }

  TRI_index_t* idx = &cap->base;

  TRI_InitIndex(idx, iid, TRI_IDX_TYPE_CAP_CONSTRAINT, document, false, false);
  TRI_InitVectorString(&idx->_fields, TRI_CORE_MEM_ZONE);

  idx->memory      = MemoryCapConstraint;
  idx->json        = JsonCapConstraint;
  idx->removeIndex = RemoveIndexCapConstraint;
  idx->insert      = InsertCapConstraint;
  idx->postInsert  = PostInsertCapConstraint;
  idx->remove      = RemoveCapConstraint;

  cap->_count      = count;
  cap->_size       = size;

  InitialiseCap(cap, document);

  return idx;
}
示例#2
0
TRI_index_t* TRI_CreateHashIndex (struct TRI_primary_collection_s* primary,
                                  TRI_vector_pointer_t* fields,
                                  TRI_vector_t* paths,
                                  bool unique,
                                  size_t initialDocumentCount) {
  TRI_hash_index_t* hashIndex;
  TRI_index_t* idx;
  int res;

  // ...........................................................................
  // Initialize the index and the callback functions
  // ...........................................................................

  hashIndex = TRI_Allocate(TRI_CORE_MEM_ZONE, sizeof(TRI_hash_index_t), false);
  idx = &hashIndex->base;

  idx->typeName = TypeNameHashIndex;
  TRI_InitIndex(idx, TRI_IDX_TYPE_HASH_INDEX, primary, unique, true);
  
  idx->json     = JsonHashIndex;
  idx->insert   = InsertHashIndex;
  idx->remove   = RemoveHashIndex;

  // ...........................................................................
  // Copy the contents of the path list vector into a new vector and store this
  // ...........................................................................

  TRI_CopyPathVector(&hashIndex->_paths, paths);

  TRI_InitVectorString(&idx->_fields, TRI_CORE_MEM_ZONE);
  TRI_CopyDataVectorStringFromVectorPointer(TRI_CORE_MEM_ZONE, &idx->_fields, fields);

  // create a index preallocated for the current number of documents
  res = TRI_InitHashArray(&hashIndex->_hashArray,
                          initialDocumentCount,
                          hashIndex->_paths._length);

  // oops, out of memory?
  if (res != TRI_ERROR_NO_ERROR) {
    TRI_DestroyVector(&hashIndex->_paths);
    TRI_DestroyVectorString(&idx->_fields);
    TRI_Free(TRI_CORE_MEM_ZONE, hashIndex);
    return NULL;
  }

  // ...........................................................................
  // Assign the function calls used by the query engine
  // ...........................................................................

  idx->indexQuery = NULL;
  idx->indexQueryFree = NULL;
  idx->indexQueryResult = NULL;

  return idx;
}
示例#3
0
TRI_index_t* TRI_CreateGeo2Index (TRI_document_collection_t* document,
                                  TRI_idx_iid_t iid,
                                  char const* latitudeName,
                                  TRI_shape_pid_t latitude,
                                  char const* longitudeName,
                                  TRI_shape_pid_t longitude,
                                  bool unique,
                                  bool ignoreNull) {
  char* lat;
  char* lon;

  TRI_geo_index_t* geo = static_cast<TRI_geo_index_t*>(TRI_Allocate(TRI_CORE_MEM_ZONE, sizeof(TRI_geo_index_t), false));
  TRI_index_t* idx = &geo->base;

  TRI_InitVectorString(&idx->_fields, TRI_CORE_MEM_ZONE);

  TRI_InitIndex(idx, iid, TRI_IDX_TYPE_GEO2_INDEX, document, unique);

  idx->_ignoreNull = ignoreNull;

  idx->memory   = MemoryGeoIndex;
  idx->json     = JsonGeo2Index;
  idx->insert   = InsertGeoIndex;
  idx->remove   = RemoveGeoIndex;

  lat = TRI_DuplicateStringZ(TRI_CORE_MEM_ZONE, latitudeName);
  lon = TRI_DuplicateStringZ(TRI_CORE_MEM_ZONE, longitudeName);
  TRI_PushBackVectorString(&idx->_fields, lat);
  TRI_PushBackVectorString(&idx->_fields, lon);

  geo->_geoIndex = GeoIndex_new();

  // oops, out of memory?
  if (geo->_geoIndex == NULL) {
    TRI_DestroyVectorString(&idx->_fields);
    TRI_Free(TRI_CORE_MEM_ZONE, geo);
    return NULL;
  }

  geo->_variant    = INDEX_GEO_INDIVIDUAL_LAT_LON;
  geo->_location   = 0;
  geo->_latitude   = latitude;
  geo->_longitude  = longitude;

  GeoIndex_assignMethod(&(idx->indexQuery), TRI_INDEX_METHOD_ASSIGNMENT_QUERY);
  GeoIndex_assignMethod(&(idx->indexQueryFree), TRI_INDEX_METHOD_ASSIGNMENT_FREE);
  GeoIndex_assignMethod(&(idx->indexQueryResult), TRI_INDEX_METHOD_ASSIGNMENT_RESULT);

  return idx;
}
示例#4
0
TRI_index_t* TRI_CreateGeo1Index (TRI_document_collection_t* document,
                                  TRI_idx_iid_t iid,
                                  char const* locationName,
                                  TRI_shape_pid_t location,
                                  bool geoJson,
                                  bool unique,
                                  bool ignoreNull) {
  char* ln;

  TRI_geo_index_t* geo = static_cast<TRI_geo_index_t*>(TRI_Allocate(TRI_CORE_MEM_ZONE, sizeof(TRI_geo_index_t), false));
  TRI_index_t* idx = &geo->base;

  TRI_InitVectorString(&idx->_fields, TRI_CORE_MEM_ZONE);

  TRI_InitIndex(idx, iid, TRI_IDX_TYPE_GEO1_INDEX, document, unique, false);

  idx->_ignoreNull = ignoreNull;

  idx->memory   = MemoryGeoIndex;
  idx->json     = JsonGeo1Index;
  idx->insert   = InsertGeoIndex;
  idx->remove   = RemoveGeoIndex;

  ln = TRI_DuplicateStringZ(TRI_CORE_MEM_ZONE, locationName);
  TRI_PushBackVectorString(&idx->_fields, ln);

  geo->_geoIndex = GeoIndex_new();

  // oops, out of memory?
  if (geo->_geoIndex == NULL) {
    TRI_DestroyVectorString(&idx->_fields);
    TRI_Free(TRI_CORE_MEM_ZONE, geo);
    return NULL;
  }

  geo->_variant    = geoJson ? INDEX_GEO_COMBINED_LAT_LON : INDEX_GEO_COMBINED_LON_LAT;
  geo->_location   = location;
  geo->_latitude   = 0;
  geo->_longitude  = 0;
  geo->_geoJson    = geoJson;

  return idx;
}
示例#5
0
TRI_index_t* TRI_CreateCapConstraint (struct TRI_primary_collection_s* primary,
                                      size_t size) {
  TRI_cap_constraint_t* cap;
  TRI_index_t* idx;

  cap = TRI_Allocate(TRI_CORE_MEM_ZONE, sizeof(TRI_cap_constraint_t), false);
  idx = &cap->base;

  idx->typeName = TypeNameCapConstraint;
  TRI_InitIndex(idx, TRI_IDX_TYPE_CAP_CONSTRAINT, primary, false, true);

  idx->json        = JsonCapConstraint;
  idx->removeIndex = RemoveIndexCapConstraint;
  idx->insert      = InsertCapConstraint;
  idx->postInsert  = PostInsertCapConstraint;
  idx->remove      = RemoveCapConstraint;

  cap->_size = size;

  InitialiseCap(cap, primary);

  return idx;
}