mirror of
https://github.com/Unidata/netcdf-c.git
synced 2024-12-27 08:49:16 +08:00
25f062528b
The file docs/indexing.dox tries to provide design information for the refactoring. The primary change is to replace all walking of linked lists with the use of the NCindex data structure. Ncindex is a combination of a hash table (for name-based lookup) and a vector (for walking the elements in the index). Additionally, global vectors are added to NC_HDF5_FILE_INFO_T to support direct mapping of an e.g. dimid to the NC_DIM_INFO_T object. These global vectors exist for dimensions, types, and groups because they have globally unique id numbers. WARNING: 1. since libsrc4 and libsrchdf4 share code, there are also changes in libsrchdf4. 2. Any outstanding pull requests that change libsrc4 or libhdf4 are likely to cause conflicts with this code. 3. The original reason for doing this was for performance improvements, but as noted elsewhere, this may not be significant because the meta-data read performance apparently is being dominated by the hdf5 library because we do bulk meta-data reading rather than lazy reading.
111 lines
3.2 KiB
C
111 lines
3.2 KiB
C
/*
|
|
Copyright (c) 1998-2017 University Corporation for Atmospheric Research/Unidata
|
|
See LICENSE.txt for license information.
|
|
*/
|
|
|
|
#ifndef NCINDEX_H
|
|
#define NCINDEX_H
|
|
|
|
/* If defined, then the hashmap is used.
|
|
This for performance experimentation
|
|
*/
|
|
#undef NCNOHASH
|
|
|
|
#undef NCINDEXDEBUG
|
|
|
|
#include "nclist.h"
|
|
#include "nchashmap.h" /* Also includes name map and id map */
|
|
|
|
/* Forward (see nc4internal.h)*/
|
|
struct NC_OBJ;
|
|
|
|
/*
|
|
This index data structure is an ordered list of objects. It is
|
|
used pervasively in libsrc4 to store metadata relationships.
|
|
The goal is to provide by-name and i'th indexed access (via
|
|
NClist) to the objects in the index. Using NCindex might be
|
|
overkill for some relationships, but we can sort that out later.
|
|
As a rule, we use this to store definitional relationships such
|
|
as (in groups) dimension definitions, variable definitions, type
|
|
defs and subgroup defs. We do not, as a rule, use this to store
|
|
reference relationships such as the list of dimensions for a
|
|
variable.
|
|
|
|
See docs/indexind.dox for more detailed documentation
|
|
|
|
*/
|
|
|
|
/* Generic list + matching hashtable */
|
|
typedef struct NCindex {
|
|
NClist* list;
|
|
#ifndef NCNOHASH
|
|
NC_hashmap* map;
|
|
#endif
|
|
} NCindex;
|
|
|
|
/* Locate object by name in an NCindex */
|
|
extern struct NC_OBJ* ncindexlookup(NCindex* index, const char* name);
|
|
|
|
/* Get ith object in the index vector */
|
|
extern struct NC_OBJ* ncindexith(NCindex* index, size_t i);
|
|
|
|
/* See if x is contained in the index and return its vector permission*/
|
|
extern int ncindexfind(NCindex* index, struct NC_OBJ* o);
|
|
|
|
/* Add object to the end of the vector, also insert into the hashmaps; */
|
|
/* Return 1 if ok, 0 otherwise.*/
|
|
extern int ncindexadd(NCindex* index, struct NC_OBJ* obj);
|
|
|
|
/* Insert object at ith position of the vector, also insert into the hashmaps; */
|
|
/* Return 1 if ok, 0 otherwise.*/
|
|
extern int ncindexset(NCindex* index, size_t i, struct NC_OBJ* obj);
|
|
|
|
/* Get a copy of the vector contents */
|
|
extern struct NC_OBJ** ncindexdup(NCindex* index);
|
|
|
|
/* Count the non-null entries in an NCindex */
|
|
extern int ncindexcount(NCindex* index);
|
|
|
|
/* Rebuild index using all objects in the vector */
|
|
/* Return 1 if ok, 0 otherwise.*/
|
|
extern int ncindexrebuild(NCindex* index);
|
|
|
|
/* "Remove" ith object from the index;
|
|
WARNING: Replaces it with NULL in the list.
|
|
*/
|
|
/* Return 1 if ok, 0 otherwise.*/
|
|
extern int ncindexidel(NCindex* index,size_t i);
|
|
|
|
/* Free an index. */
|
|
/* Return 1 if ok; 0 otherwise */
|
|
extern int ncindexfree(NCindex* index);
|
|
|
|
/* Create an index: size == 0 => use defaults */
|
|
/* Return index if ok; NULL otherwise */
|
|
extern NCindex* ncindexnew(size_t initsize);
|
|
|
|
extern int ncindexverify(NCindex* lm, int dump);
|
|
|
|
/* Lookup object in index; return NULL if not found */
|
|
extern struct NC_OBJ* ncindexlookup(NCindex*, const char* name);
|
|
|
|
/* Inline functions */
|
|
|
|
/* Test if index has been initialized */
|
|
#define ncindexinitialized(index) ((index) != NULL && (index)->list != NULL)
|
|
|
|
/* Get number of entries in an index */
|
|
#ifdef NCINDEXDEBUG
|
|
static int ncindexsize(NCindex* index)
|
|
{
|
|
int i;
|
|
if(index == NULL) return 0;
|
|
i = nclistlength(index->list);
|
|
return i;
|
|
}
|
|
#else
|
|
#define ncindexsize(index) ((index)==NULL?0:(nclistlength((index)->list)))
|
|
#endif
|
|
|
|
#endif /*ncindexH*/
|