Commit 15c7ddaf authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

cdi_key_compare: changed interface.

parent 693f0f3d
......@@ -19,19 +19,10 @@
static
cdi_atts_t *get_attsp(vlist_t *vlistptr, int varID)
{
cdi_atts_t *attsp = NULL;
if ( varID == CDI_GLOBAL ) return &vlistptr->atts;
else if ( varID >= 0 && varID < vlistptr->nvars ) return &(vlistptr->vars[varID].atts);
if ( varID == CDI_GLOBAL )
{
attsp = &vlistptr->atts;
}
else
{
if ( varID >= 0 && varID < vlistptr->nvars )
attsp = &(vlistptr->vars[varID].atts);
}
return attsp;
return NULL;
}
static
......@@ -466,16 +457,13 @@ int cdiAttTypeLookup(cdi_att_t *attp)
int cdi_att_compare(vlist_t *a, int varIDA, vlist_t *b, int varIDB, int attnum)
{
cdi_atts_t *attspa = get_attsp(a, varIDA),
*attspb = get_attsp(b, varIDB);
if (attspa == NULL && attspb == NULL)
return 0;
xassert(attnum >= 0 && attnum < (int)attspa->nelems
&& attnum < (int)attspb->nelems);
*attspb = get_attsp(b, varIDB);
if (attspa == NULL && attspb == NULL) return 0;
xassert(attnum >= 0 && attnum < (int)attspa->nelems && attnum < (int)attspb->nelems);
cdi_att_t *attpa = attspa->value + attnum,
*attpb = attspb->value + attnum;
*attpb = attspb->value + attnum;
size_t len;
if ((len = attpa->namesz) != attpb->namesz)
return 1;
if ((len = attpa->namesz) != attpb->namesz) return 1;
int diff;
if ((diff = memcmp(attpa->name, attpb->name, len)))
return 1;
......@@ -483,6 +471,7 @@ int cdi_att_compare(vlist_t *a, int varIDA, vlist_t *b, int varIDB, int attnum)
|| attpa->exdtype != attpb->exdtype
|| attpa->nelems != attpb->nelems)
return 1;
return memcmp(attpa->xvalue, attpb->xvalue, attpa->xsz);
}
......
......@@ -86,36 +86,19 @@ const cdi_key_t *find_key_const(const cdi_keys_t *keysp, int key)
static
cdi_keys_t *cdi_get_keysp(int objID, int varID)
{
cdi_keys_t *keysp = NULL;
if ( reshGetTxCode(objID) == GRID ) return grid_get_keysp(grid_to_pointer(objID), varID);
else if ( reshGetTxCode(objID) == ZAXIS ) return zaxis_get_keysp(zaxis_to_pointer(objID), varID);
else if ( reshGetTxCode(objID) == VLIST ) return vlist_get_keysp(vlist_to_pointer(objID), varID);
if ( reshGetTxCode(objID) == GRID )
{
grid_t *gridptr = grid_to_pointer(objID);
keysp = grid_get_keysp(gridptr, varID);
}
else if ( reshGetTxCode(objID) == ZAXIS )
{
zaxis_t *zaxisptr = zaxis_to_pointer(objID);
keysp = zaxis_get_keysp(zaxisptr, varID);
}
else if ( reshGetTxCode(objID) == VLIST )
{
vlist_t *vlistptr = vlist_to_pointer(objID);
keysp = vlist_get_keysp(vlistptr, varID);
}
return keysp;
return NULL;
}
int vlist_key_compare(vlist_t *a, int varIDA, vlist_t *b, int varIDB, int keynum)
int cdi_key_compare(cdi_keys_t *keyspa, cdi_keys_t *keyspb, int keynum)
{
cdi_keys_t *keyspa = vlist_get_keysp(a, varIDA),
*keyspb = vlist_get_keysp(b, varIDB);
if (keyspa == NULL && keyspb == NULL) return 0;
xassert(keynum >= 0 && keynum < (int)keyspa->nelems && keynum < (int)keyspb->nelems);
cdi_key_t *keypa = keyspa->value + keynum,
*keypb = keyspb->value + keynum;
*keypb = keyspb->value + keynum;
if ( keypa->key != keypb->key ) return 1;
......
......@@ -58,6 +58,8 @@ void cdiPrintKeys(int cdiID, int varID);
void cdiInitKeys(cdi_keys_t *keysp);
int cdi_key_compare(cdi_keys_t *keyspa, cdi_keys_t *keyspb, int keynum);
#endif
/*
......
......@@ -1541,12 +1541,11 @@ static int vlistTxCode ( void )
static
int vlistGetSizeP ( void * vlistptr, void *context)
{
int txsize, varID;
vlist_t *p = (vlist_t*) vlistptr;
txsize = serializeGetSize(vlist_nints, CDI_DATATYPE_INT, context);
int txsize = serializeGetSize(vlist_nints, CDI_DATATYPE_INT, context);
txsize += serializeGetSize(1, CDI_DATATYPE_LONG, context);
txsize += cdiAttsGetSize(p, CDI_GLOBAL, context);
for ( varID = 0; varID < p->nvars; varID++ )
for ( int varID = 0; varID < p->nvars; varID++ )
txsize += vlistVarGetPackSize(p, varID, context);
return txsize;
}
......@@ -1556,7 +1555,7 @@ static
void vlistPackP ( void * vlistptr, void * buf, int size, int *position,
void *context )
{
int varID, tempbuf[vlist_nints];
int tempbuf[vlist_nints];
vlist_t *p = (vlist_t*) vlistptr;
tempbuf[0] = p->self;
tempbuf[1] = p->nvars;
......@@ -1568,7 +1567,7 @@ void vlistPackP ( void * vlistptr, void * buf, int size, int *position,
serializePack(&p->ntsteps, 1, CDI_DATATYPE_LONG, buf, size, position, context);
cdiAttsPack(p, CDI_GLOBAL, buf, size, position, context);
for ( varID = 0; varID < p->nvars; varID++ )
for ( int varID = 0; varID < p->nvars; varID++ )
{
vlistVarPack(p, varID, (char *)buf, size, position, context);
}
......@@ -1594,19 +1593,16 @@ void vlistUnpack(char * buf, int size, int *position, int originNamespace,
cdiAttsUnpack(targetID, CDI_GLOBAL, buf, size, position, context);
for (int varID = 0; varID < nvars; varID++ )
vlistVarUnpack(targetID, buf, size, position, originNamespace, context);
reshSetStatus(targetID, &vlistOps,
reshGetStatus(targetID, &vlistOps) & ~RESH_SYNC_BIT);
reshSetStatus(targetID, &vlistOps, reshGetStatus(targetID, &vlistOps) & ~RESH_SYNC_BIT);
}
void vlist_check_contents(int vlistID)
{
int zaxisID;
int nzaxis = vlistNzaxis(vlistID);
for ( int index = 0; index < nzaxis; index++ )
{
zaxisID = vlistZaxis(vlistID, index);
int zaxisID = vlistZaxis(vlistID, index);
if ( zaxisInqType(zaxisID) == ZAXIS_GENERIC )
cdiCheckZaxis(zaxisID);
}
......
......@@ -118,8 +118,6 @@ typedef struct
vlist_t;
int vlist_key_compare(vlist_t *a, int varIDA, vlist_t *b, int varIDB, int keynum);
vlist_t *vlist_to_pointer(int vlistID);
void cdiVlistMakeInternal(int vlistID);
void cdiVlistMakeImmutable(int vlistID);
......
......@@ -1954,7 +1954,7 @@ int vlistVarCompare(vlist_t *a, int varIDA, vlist_t *b, int varIDB)
size_t nkeys = a->vars[varIDA].keys.nelems;
if (nkeys != b->vars[varIDB].keys.nelems) return 1;
for (size_t keyID = 0; keyID < nkeys; ++keyID)
diff |= vlist_key_compare(a, varIDA, b, varIDB, (int)keyID);
diff |= cdi_key_compare(&a->vars[varIDA].keys, &b->vars[varIDB].keys, (int)keyID);
return diff;
}
......@@ -2003,8 +2003,7 @@ int vlistVarGetPackSize(vlist_t *p, int varID, void *context)
varsize += serializeGetSize((int)strlen(var->units), CDI_DATATYPE_TXT, context);
if (var->extra)
varsize += serializeGetSize((int)strlen(var->extra), CDI_DATATYPE_TXT, context);
varsize += serializeGetSize(4 * zaxisInqSize(var->zaxisID),
CDI_DATATYPE_INT, context);
varsize += serializeGetSize(4 * zaxisInqSize(var->zaxisID), CDI_DATATYPE_INT, context);
varsize += cdiAttsGetSize(p, varID, context);
return varsize;
}
......
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