|
|
@ -117,16 +117,18 @@ int mdb_midl_insert( MDB_IDL ids, MDB_ID id ) |
|
|
|
} |
|
|
|
} |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
MDB_IDL mdb_midl_alloc(void) |
|
|
|
MDB_IDL mdb_midl_alloc(int num) |
|
|
|
{ |
|
|
|
{ |
|
|
|
MDB_IDL ids = malloc((MDB_IDL_UM_MAX+1) * sizeof(MDB_ID)); |
|
|
|
MDB_IDL ids = malloc((num+2) * sizeof(MDB_ID)); |
|
|
|
*ids++ = MDB_IDL_UM_MAX; |
|
|
|
if (ids) |
|
|
|
|
|
|
|
*ids++ = num; |
|
|
|
return ids; |
|
|
|
return ids; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void mdb_midl_free(MDB_IDL ids) |
|
|
|
void mdb_midl_free(MDB_IDL ids) |
|
|
|
{ |
|
|
|
{ |
|
|
|
free(ids-1); |
|
|
|
if (ids) |
|
|
|
|
|
|
|
free(ids-1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int mdb_midl_shrink( MDB_IDL *idp ) |
|
|
|
int mdb_midl_shrink( MDB_IDL *idp ) |
|
|
@ -141,19 +143,26 @@ int mdb_midl_shrink( MDB_IDL *idp ) |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int mdb_midl_grow( MDB_IDL *idp, int num ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
MDB_IDL idn = *idp-1; |
|
|
|
|
|
|
|
/* grow it */ |
|
|
|
|
|
|
|
idn = realloc(idn, (*idn + num + 2) * sizeof(MDB_ID)); |
|
|
|
|
|
|
|
if (!idn) |
|
|
|
|
|
|
|
return ENOMEM; |
|
|
|
|
|
|
|
*idn++ += num; |
|
|
|
|
|
|
|
*idp = idn; |
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int mdb_midl_append( MDB_IDL *idp, MDB_ID id ) |
|
|
|
int mdb_midl_append( MDB_IDL *idp, MDB_ID id ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
MDB_IDL ids = *idp; |
|
|
|
MDB_IDL ids = *idp; |
|
|
|
/* Too big? */ |
|
|
|
/* Too big? */ |
|
|
|
if (ids[0] >= ids[-1]) { |
|
|
|
if (ids[0] >= ids[-1]) { |
|
|
|
MDB_IDL idn = ids-1; |
|
|
|
if (mdb_midl_grow(idp, MDB_IDL_UM_MAX)) |
|
|
|
/* grow it */ |
|
|
|
return ENOMEM; |
|
|
|
idn = realloc(idn, (*idn + MDB_IDL_UM_MAX + 1) * sizeof(MDB_ID)); |
|
|
|
ids = *idp; |
|
|
|
if (!idn) |
|
|
|
|
|
|
|
return -1; |
|
|
|
|
|
|
|
*idn++ += MDB_IDL_UM_MAX; |
|
|
|
|
|
|
|
ids = idn; |
|
|
|
|
|
|
|
*idp = ids; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
ids[0]++; |
|
|
|
ids[0]++; |
|
|
|
ids[ids[0]] = id; |
|
|
|
ids[ids[0]] = id; |
|
|
@ -165,14 +174,9 @@ int mdb_midl_append_list( MDB_IDL *idp, MDB_IDL app ) |
|
|
|
MDB_IDL ids = *idp; |
|
|
|
MDB_IDL ids = *idp; |
|
|
|
/* Too big? */ |
|
|
|
/* Too big? */ |
|
|
|
if (ids[0] + app[0] >= ids[-1]) { |
|
|
|
if (ids[0] + app[0] >= ids[-1]) { |
|
|
|
MDB_IDL idn = ids-1; |
|
|
|
if (mdb_midl_grow(idp, app[0])) |
|
|
|
/* grow it */ |
|
|
|
return ENOMEM; |
|
|
|
idn = realloc(idn, (*idn + app[-1]) * sizeof(MDB_ID)); |
|
|
|
ids = *idp; |
|
|
|
if (!idn) |
|
|
|
|
|
|
|
return -1; |
|
|
|
|
|
|
|
*idn++ += app[-1]; |
|
|
|
|
|
|
|
ids = idn; |
|
|
|
|
|
|
|
*idp = ids; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
memcpy(&ids[ids[0]+1], &app[1], app[0] * sizeof(MDB_ID)); |
|
|
|
memcpy(&ids[ids[0]+1], &app[1], app[0] * sizeof(MDB_ID)); |
|
|
|
ids[0] += app[0]; |
|
|
|
ids[0] += app[0]; |
|
|
|