Xmipp  v3.23.11-Nereus
Functions
stack.cpp File Reference
#include "defines.h"
#include "stack.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
Include dependency graph for stack.cpp:

Go to the source code of this file.

Functions

int initialize_Stack (struct stack_T *stack, int size)
 
struct Convex_T peak (struct stack_T *stack)
 
struct Convex_T peak_Prev (struct stack_T *stack)
 
void update_Peak (struct stack_T *stack, int edge)
 
void push (struct stack_T *stack, struct Convex_T edge)
 
void pop (struct stack_T *stack)
 
int get_Stack_nElements (struct stack_T *stack)
 
void reset_Stack (struct stack_T *stack)
 
void print_Stack (struct stack_T *stack)
 
void finalize_Stack (struct stack_T *stack)
 

Function Documentation

◆ finalize_Stack()

void finalize_Stack ( struct stack_T stack)

Definition at line 96 of file stack.cpp.

97 {
98  // Deallocate memory.
99  stack->size = 0;
100  stack->nElements = 0;
101  if (stack->data != NULL)
102  {
103  free(stack->data);
104  stack->data = NULL;
105  }
106 }
int size
Definition: stack.h:17
free((char *) ob)
int nElements
Definition: stack.h:18
struct Convex_T * data
Definition: stack.h:19

◆ get_Stack_nElements()

int get_Stack_nElements ( struct stack_T stack)

Definition at line 69 of file stack.cpp.

70 {
71  // Return number of elements.
72  return(stack->nElements);
73 }
int nElements
Definition: stack.h:18

◆ initialize_Stack()

int initialize_Stack ( struct stack_T stack,
int  size 
)

Definition at line 10 of file stack.cpp.

11 {
12  int ret=SUCCESS; // Return value.
13 
14  // Initialize stack attributes.
15  stack->size = size;
16  stack->nElements = 0;
17  stack->data = (struct Convex_T *) malloc(sizeof(struct Convex_T)*size);
18 
19  // Check error allocating memory.
20  if (stack->data == NULL)
21  {
22  ret = FAILURE;
23  printf("Error allocating memory in initialize_Stack");
24 #ifdef LOGGING
25  sprintf( log_Text, "Error allocating memory in initialize_Stack\n");
26  write_Log( log_Text);
27 #endif
28  }
29 
30  return(ret);
31 }
#define FAILURE
Definition: defines.h:20
int size
Definition: stack.h:17
#define SUCCESS
Definition: defines.h:21
int nElements
Definition: stack.h:18
Definition: stack.h:9
struct Convex_T * data
Definition: stack.h:19

◆ peak()

struct Convex_T peak ( struct stack_T stack)

Definition at line 33 of file stack.cpp.

34 {
35  // Get peak element of the stack.
36  return(stack->data[stack->nElements-1]);
37 }
int nElements
Definition: stack.h:18
struct Convex_T * data
Definition: stack.h:19

◆ peak_Prev()

struct Convex_T peak_Prev ( struct stack_T stack)

Definition at line 39 of file stack.cpp.

40 {
41  // Get the top 2 elements of the stack.
42  return(stack->data[stack->nElements-2]);
43 }
int nElements
Definition: stack.h:18
struct Convex_T * data
Definition: stack.h:19

◆ pop()

void pop ( struct stack_T stack)

Definition at line 59 of file stack.cpp.

60 {
61  // Check if stack is not empty.
62  if (stack->nElements > 0)
63  {
64  // Decrease number of elements.
65  stack->nElements--;
66  }
67 }
int nElements
Definition: stack.h:18

◆ print_Stack()

void print_Stack ( struct stack_T stack)

Definition at line 82 of file stack.cpp.

83 {
84  int i=0; // Loop counter.
85 
86  // Print all elements in stack.
87  for (i=0; i<stack->nElements ;i++)
88  {
89  printf("Position: %d. Edge id: %d with origin vertex %d.\n",
90  i,
91  stack->data[i].edge_ID,
92  stack->data[i].vertex_Index);
93  }
94 }
#define i
int vertex_Index
Definition: stack.h:11
int edge_ID
Definition: stack.h:12
int nElements
Definition: stack.h:18
struct Convex_T * data
Definition: stack.h:19

◆ push()

void push ( struct stack_T stack,
struct Convex_T  edge 
)

Definition at line 51 of file stack.cpp.

52 {
53  // Insert a new element in the top of the stack.
54  stack->data[stack->nElements] = edge;
55  stack->nElements++;
56 }
int nElements
Definition: stack.h:18
struct Convex_T * data
Definition: stack.h:19

◆ reset_Stack()

void reset_Stack ( struct stack_T stack)

Definition at line 75 of file stack.cpp.

76 {
77  // Reset data of the stack (without resizing).
78  stack->nElements = 0;
79  memset( stack->data, 0, sizeof(struct Convex_T)*stack->size);
80 }
int size
Definition: stack.h:17
int nElements
Definition: stack.h:18
Definition: stack.h:9
struct Convex_T * data
Definition: stack.h:19

◆ update_Peak()

void update_Peak ( struct stack_T stack,
int  edge 
)

Definition at line 45 of file stack.cpp.

46 {
47  // Update edge of peak of the stack.
48  stack->data[stack->nElements-1].edge_ID = edge;
49 }
int edge_ID
Definition: stack.h:12
int nElements
Definition: stack.h:18
struct Convex_T * data
Definition: stack.h:19