• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

estebanzimanyi / MobilityDB / 10027097873

21 Jul 2024 09:02AM UTC coverage: 94.979% (-0.1%) from 95.092%
10027097873

push

github

estebanzimanyi
Add spansDuration function

0 of 39 new or added lines in 2 files covered. (0.0%)

1 existing line in 1 file now uncovered.

32007 of 33699 relevant lines covered (94.98%)

757643.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/meos/src/general/bboxarray.c
1
/*****************************************************************************
2
 *
3
 * This MobilityDB code is provided under The PostgreSQL License.
4
 * Copyright (c) 2016-2024, Université libre de Bruxelles and MobilityDB
5
 * contributors
6
 *
7
 * MobilityDB includes portions of PostGIS version 3 source code released
8
 * under the GNU General Public License (GPLv2 or later).
9
 * Copyright (c) 2001-2024, PostGIS contributors
10
 *
11
 * Permission to use, copy, modify, and distribute this software and its
12
 * documentation for any purpose, without fee, and without a written
13
 * agreement is hereby granted, provided that the above copyright notice and
14
 * this paragraph and the following two paragraphs appear in all copies.
15
 *
16
 * IN NO EVENT SHALL UNIVERSITE LIBRE DE BRUXELLES BE LIABLE TO ANY PARTY FOR
17
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING
18
 * LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
19
 * EVEN IF UNIVERSITE LIBRE DE BRUXELLES HAS BEEN ADVISED OF THE POSSIBILITY
20
 * OF SUCH DAMAGE.
21
 *
22
 * UNIVERSITE LIBRE DE BRUXELLES SPECIFICALLY DISCLAIMS ANY WARRANTIES,
23
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
24
 * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON
25
 * AN "AS IS" BASIS, AND UNIVERSITE LIBRE DE BRUXELLES HAS NO OBLIGATIONS TO
26
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
27
 *
28
 *****************************************************************************/
29

30
/**
31
 * @brief STBox expandable array type.
32
 */
33

34
#include "general/bboxarray.h"
35

36
/* C */
37
#include <assert.h>
38
#include <limits.h>
39
/* PostgreSQL */
40
#include <postgres.h>
41
#if MEOS
42
  #define MaxAllocSize   ((Size) 0x3fffffff) /* 1 gigabyte - 1 */
43
#else
44
  #include <utils/memutils.h>
45
#endif /* MEOS */
46
/* MEOS */
47
#include <meos.h>
48
#include <general/temporal_boxops.h>
49

50
/*****************************************************************************/
51

52
/**
53
 * @brief Return the position to store an additional element in the array
54
 * @return On error return @p INT_MAX
55
 */
56
static int
NEW
57
bboxarray_alloc(BBoxArray *array, size_t boxsize)
×
58
{
59
  /* Increase the number of values stored in the array */
NEW
60
  array->count++;
×
61

62
  /* If there is no more available space expand the list */
NEW
63
  if (array->count >= array->maxcount)
×
64
  {
65
    /* PostgreSQL has a limit of MaxAllocSize = 1 gigabyte - 1. By default,
66
     * the array doubles the size when expanded. If doubling the size goes
67
     * beyond MaxAllocSize, we allocate the maximum number of elements that
68
     * fit within MaxAllocSize. If this maximum has been previously reached
69
     * and more capacity is required, an error is generated. */
NEW
70
    if (array->maxcount == (int) floor(MaxAllocSize / boxsize))
×
71
    {
NEW
72
      meos_error(ERROR, MEOS_ERR_MEMORY_ALLOC_ERROR,
×
73
        "No more memory available to compute the bounding boxes");
NEW
74
      return INT_MAX;
×
75
    }
NEW
76
    if (boxsize * (array->maxcount << 2) > MaxAllocSize)
×
NEW
77
      array->maxcount = (int) floor(MaxAllocSize / boxsize);
×
78
    else
NEW
79
      array->maxcount <<= BBOXARRAY_GROW;
×
NEW
80
    array->elems = repalloc(array->elems, sizeof(STBox *) * array->maxcount);
×
81
  }
82

83
  /* Return the first available entry */
NEW
84
  array->count++;
×
NEW
85
  return array->count - 1;
×
86
}
87

88
/**
89
 * @brief Constructs a array from the array of values values
90
 * @param[in] values Array of values
91
 * @param[in] count Number of elements in the array
92
 */
93
BBoxArray *
NEW
94
bboxarray_make(meosType boxtype, int count)
×
95
{
96
  assert(count > 0);
NEW
97
  BBoxArray *result = palloc0(sizeof(BBoxArray));
×
NEW
98
  size_t boxsize = bbox_get_size(boxtype);
×
NEW
99
  result->elems = palloc0(boxsize * BBOXARRAY_INITIAL_CAPACITY);
×
NEW
100
  result->boxtype = boxtype;
×
NEW
101
  result->boxsize = boxsize;
×
NEW
102
  result->maxcount = BBOXARRAY_INITIAL_CAPACITY;
×
NEW
103
  return result;
×
104
}
105

106
/**
107
 * @ingroup meos_internal_temporal_agg
108
 * @brief Delete the stbox array and free its allocated memory
109
 * @param[in] array Bounding box array
110
 */
111
void
NEW
112
bboxarray_free(BBoxArray *array)
×
113
{
NEW
114
  if (! array)
×
115
    return;
NEW
116
  if (array->elems)
×
NEW
117
    pfree(array->elems);
×
NEW
118
  pfree(array);
×
NEW
119
  return;
×
120
}
121

122
/**
123
 * @brief Constructs a array from the array of values values
124
 * @param[in] values Array of values
125
 * @param[in] count Number of elements in the array
126
 */
127
bool
NEW
128
bboxarray_add(const void *box, BBoxArray *array)
×
129
{
130
  assert(box);
NEW
131
  int count = bboxarray_alloc(array, array->boxsize);
×
NEW
132
  if (count == INT_MAX)
×
133
    return false;
NEW
134
  uint8_t *elemptr = ((uint8_t *) array->elems) + (array->boxsize * (count - 1));
×
135
  memcpy(elemptr, box, array->boxsize);
NEW
136
  return true;
×
137
}
138

139
/*****************************************************************************/
140

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc