LCOV - code coverage report
Current view: top level - sql/common - sql_stack.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 18 31 58.1 %
Date: 2024-04-25 20:03:45 Functions: 5 7 71.4 %

          Line data    Source code
       1             : /*
       2             :  * SPDX-License-Identifier: MPL-2.0
       3             :  *
       4             :  * This Source Code Form is subject to the terms of the Mozilla Public
       5             :  * License, v. 2.0.  If a copy of the MPL was not distributed with this
       6             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       7             :  *
       8             :  * Copyright 2024 MonetDB Foundation;
       9             :  * Copyright August 2008 - 2023 MonetDB B.V.;
      10             :  * Copyright 1997 - July 2008 CWI.
      11             :  */
      12             : 
      13             : #include "monetdb_config.h"
      14             : #include "sql_stack.h"
      15             : 
      16             : sql_stack *
      17      759202 : sql_stack_new(sql_allocator *sa, int size)
      18             : {
      19      759202 :         assert(sa);
      20      759202 :         sql_stack *s = SA_NEW(sa, sql_stack);
      21      759200 :         if (s == NULL)
      22             :                 return NULL;
      23             : 
      24     1518399 :         *s = (sql_stack) {
      25             :                 .sa = sa,
      26             :                 .size = size,
      27      759200 :                 .values = SA_NEW_ARRAY(sa, void*, size),
      28             :         };
      29      759199 :         if (s->values == NULL) {
      30             :                 //_DELETE(s);
      31             :                 return NULL;
      32             :         }
      33             :         return s;
      34             : }
      35             : 
      36             : void
      37       34149 : sql_stack_push(sql_stack *s, void *v)
      38             : {
      39       34149 :         if (s->top >= s->size) {
      40           0 :                 void **nvalues;
      41           0 :                 int osz = s->size;
      42             : 
      43           0 :                 s->size *= 2;
      44           0 :                 nvalues = SA_RENEW_ARRAY(s->sa, void*, s->values, s->size, osz);
      45           0 :                 if (nvalues == NULL) {
      46           0 :                         s->size = osz;
      47           0 :                         return;
      48             :                 }
      49           0 :                 s->values = nvalues;
      50             :         }
      51       34149 :         s->values[s->top++] = v;
      52             : }
      53             : 
      54             : void *
      55       34149 : sql_stack_pop(sql_stack *s)
      56             : {
      57       34149 :         if (s->top == 0)
      58             :                 return NULL;
      59       34149 :         return s->values[--s->top];
      60             : }
      61             : 
      62             : void *
      63           0 : sql_stack_peek(sql_stack *s, int p)
      64             : {
      65           0 :         if (p>=s->top)
      66             :                 return NULL;
      67           0 :         return s->values[(s->top-1)-p];
      68             : }
      69             : 
      70             : void *
      71       38899 : sql_stack_fetch(sql_stack *s, int p)
      72             : {
      73       38899 :         if (p>=s->top)
      74             :                 return NULL;
      75       38879 :         return s->values[p];
      76             : }
      77             : 
      78             : int
      79      706947 : sql_stack_top(sql_stack *s)
      80             : {
      81      706947 :         return s->top;
      82             : }
      83             : 
      84             : int
      85           0 : sql_stack_empty(sql_stack *s)
      86             : {
      87           0 :         return (s->top == 0);
      88             : }

Generated by: LCOV version 1.14