Sha256: c7c6bb76d735a43714f29381c076223d1cf5b43a564ffd25e26ea75fdfbe5e80

Contents?: true

Size: 1.07 KB

Versions: 65

Compression:

Stored size: 1.07 KB

Contents

#include "stack.h"
#include <string.h>

int
stack_grow(struct stack *st, size_t new_size)
{
	void **new_st;

	if (st->asize >= new_size)
		return 0;

	new_st = realloc(st->item, new_size * sizeof(void *));
	if (new_st == NULL)
		return -1;

	memset(new_st + st->asize, 0x0,
		(new_size - st->asize) * sizeof(void *));

	st->item = new_st;
	st->asize = new_size;

	if (st->size > new_size)
		st->size = new_size;

	return 0;
}

void
stack_free(struct stack *st)
{
	if (!st)
		return;

	free(st->item);

	st->item = NULL;
	st->size = 0;
	st->asize = 0;
}

int
stack_init(struct stack *st, size_t initial_size)
{
	st->item = NULL;
	st->size = 0;
	st->asize = 0;

	if (!initial_size)
		initial_size = 8;

	return stack_grow(st, initial_size);
}

void *
stack_pop(struct stack *st)
{
	if (!st->size)
		return NULL;

	return st->item[--st->size];
}

int
stack_push(struct stack *st, void *item)
{
	if (stack_grow(st, st->size * 2) < 0)
		return -1;

	st->item[st->size++] = item;
	return 0;
}

void *
stack_top(struct stack *st)
{
	if (!st->size)
		return NULL;

	return st->item[st->size - 1];
}

Version data entries

65 entries across 64 versions & 8 rubygems

Version Path
tdiary-5.0.5 vendor/bundle/gems/github-markdown-0.6.9/ext/markdown/stack.c
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/github-markdown-0.6.9/ext/markdown/stack.c
tdiary-5.0.4 vendor/bundle/gems/github-markdown-0.6.9/ext/markdown/stack.c
redsnow-0.4.4 ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/src/stack.c
lounge_lizard-0.1.4 ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/src/stack.c
lounge_lizard-0.1.3 ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/src/stack.c
lounge_lizard-0.1.2 ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/src/stack.c
lounge_lizard-0.1.1 ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/src/stack.c
lounge_lizard-0.1.0 ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/src/stack.c
tdiary-4.2.1 vendor/bundle/ruby/2.2.0/gems/github-markdown-0.6.9/ext/markdown/stack.c
github-markdown-0.6.9 ext/markdown/stack.c
redsnow-0.4.3 ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/src/stack.c
redsnow-0.4.1 ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/src/stack.c
redsnow-0.4.0 ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/src/stack.c
redsnow-0.3.7 ext/snowcrash/ext/markdown-parser/ext/sundown/src/stack.c
redsnow-0.3.4 ext/snowcrash/ext/markdown-parser/ext/sundown/src/stack.c
github-markdown-0.6.8 ext/markdown/stack.c
redsnow-0.3.3 ext/snowcrash/ext/markdown-parser/ext/sundown/src/stack.c
redsnow-0.3.2 ext/snowcrash/ext/markdown-parser/ext/sundown/src/stack.c
redsnow-0.3.1 ext/snowcrash/ext/markdown-parser/ext/sundown/src/stack.c