MobilityDB/MobilityDB

Improve Code Quality

mschoema opened this issue · 3 comments

The functions tpointseqarr_stbox and tnpointseqarr_stbox do the exact same thing and could be merged into a single function.

void
tpointseqarr_stbox(const TSequence **sequences, int count, STBOX *box)
{
memcpy(box, tsequence_bbox_ptr(sequences[0]), sizeof(STBOX));
for (int i = 1; i < count; i++)
{
const STBOX *box1 = tsequence_bbox_ptr(sequences[i]);
stbox_expand(box, box1);
}
return;
}

void
tnpointseqarr_stbox(const TSequence **sequences, int count, STBOX *box)
{
tsequence_bbox(sequences[0], box);
for (int i = 1; i < count; i++)
{
const STBOX *box1 = tsequence_bbox_ptr(sequences[i]);
stbox_expand(box, box1);
}
return;
}

This might be possible with other functions, but I didn't check that yet.

Uniformize the *_make_free functions.

TInstantSet *
tinstantset_make_free(TInstant **instants, int count, bool merge)
{
if (count == 0)
{
pfree(instants);
return NULL;
}

TSequence *
tsequence_make_free(TInstant **instants, int count, bool lower_inc,
bool upper_inc, bool linear, bool normalize)
{
assert (count > 0);

TSequenceSet *
tsequenceset_make_free(TSequence **sequences, int count, bool normalize)
{
if (count == 0)
{
pfree(sequences);
return NULL;
}

The definition of the function tinstant_to_tinstantset in tinstant.h is a copy of the one in tinstantset.h and should be removed.

extern TInstantSet *tinstant_to_tinstantset(const TInstant *inst);

extern TInstantSet *tinstant_to_tinstantset(const TInstant *inst);

Solved by PR #201