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