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-12-19 23:10:26 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      813247 : sql_stack_new(allocator *sa, int size)
      18             : {
      19      813247 :         assert(sa);
      20      813247 :         sql_stack *s = SA_NEW(sa, sql_stack);
      21      813406 :         if (s == NULL)
      22             :                 return NULL;
      23             : 
      24     1626970 :         *s = (sql_stack) {
      25             :                 .sa = sa,
      26             :                 .size = size,
      27      813406 :                 .values = SA_NEW_ARRAY(sa, void*, size),
      28             :         };
      29      813564 :         if (s->values == NULL) {
      30             :                 //_DELETE(s);
      31             :                 return NULL;
      32             :         }
      33             :         return s;
      34             : }
      35             : 
      36             : void
      37       38002 : sql_stack_push(sql_stack *s, void *v)
      38             : {
      39       38002 :         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       38002 :         s->values[s->top++] = v;
      52             : }
      53             : 
      54             : void *
      55       37999 : sql_stack_pop(sql_stack *s)
      56             : {
      57       37999 :         if (s->top == 0)
      58             :                 return NULL;
      59       37999 :         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       39760 : sql_stack_fetch(sql_stack *s, int p)
      72             : {
      73       39760 :         if (p>=s->top)
      74             :                 return NULL;
      75       39745 :         return s->values[p];
      76             : }
      77             : 
      78             : int
      79      704035 : sql_stack_top(sql_stack *s)
      80             : {
      81      704035 :         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