Commit f1294baa authored by Chris Müller's avatar Chris Müller

Add CryArray for implementing dynamical heap memory

parent 4817a3af
......@@ -3,6 +3,7 @@ set(SOURCES
unittest.c
structures/single_linked_list.c
structures/double_linked_list.c
structures/array.c
)
set(HEADER
......@@ -10,6 +11,7 @@ set(HEADER
unix_colors.h
matrix.h
unittest.h
structures/array.h
structures/stack.h
structures/queue.h
structures/list.h
......
/*
* Copyright (c) 2012 Christoph Mueller <ruunhb@googlemail.com>
*
* Crystal is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Crystal is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "array.h"
#include <assert.h>
#include <string.h>
struct CryArray
{
unsigned char* data;
size_t alloc;
size_t length;
size_t extend;
size_t elementsize;
};
struct CryArray*
cry_array_new(size_t elementsize, size_t init, size_t extend)
{
struct CryArray* array = cry_malloc(struct CryArray);
array->alloc = init * elementsize;
array->length = 0;
array->extend = extend * elementsize;
array->elementsize = elementsize;
array->data = cry_calloc(unsigned char, init * elementsize);
return array;
}
void
cry_array_free(struct CryArray* array)
{
assert(array != 0);
cry_free(array->data);
cry_free(array);
}
size_t
cry_array_size(struct CryArray* array)
{
assert(array != 0);
return array->length;
}
size_t
cry_array_alloc(struct CryArray* array)
{
assert(array != 0);
return array->alloc / array->elementsize;
}
size_t
cry_array_elementsize(struct CryArray* array)
{
assert(array != 0);
return array->elementsize;
}
void
cry_array_set_alloc(struct CryArray* array, size_t range)
{
}
void
cry_array_append(struct CryArray* array, pointer data)
{
}
void
cry_array_append_range(struct CryArray* array, pointer data, size_t range)
{
}
void
cry_array_prepend(struct CryArray* array, pointer data)
{
}
void
cry_array_prepend_range(struct CryArray* array, pointer data, size_t range)
{
}
void
cry_array_insert(struct CryArray* array, pointer data)
{
}
void
cry_array_insert_range(struct CryArray* array, pointer data, size_t range)
{
}
int
cry_array_remove(struct CryArray* array, size_t index)
{
return 0;
}
int
cry_array_remove_range(struct CryArray* array, size_t index, size_t range)
{
return 0;
}
pointer
cry_array_get(struct CryArray* array, size_t index)
{
return 0;
}
/*
* Copyright (c) 2012 Christoph Mueller <ruunhb@googlemail.com>
*
* Crystal is free software: you can redistribute it and/or modify
* it under the terms of the Lesser GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Crystal is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Lesser GNU General Public License for more details.
*
* You should have received a copy of the Lesser GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef CRYSTAL_STRUCTURES_ARRAY_H
#define CRYSTAL_STRUCTURES_ARRAY_H
#include "standard.h"
struct CryArray;
struct CryArray* cry_array_new(size_t elementsize, size_t init, size_t extend);
void cry_array_free(struct CryArray* array);
size_t cry_array_size(struct CryArray* array);
size_t cry_array_alloc(struct CryArray* array);
size_t cry_array_elementsize(struct CryArray* array);
void cry_array_set_alloc(struct CryArray* array, size_t range);
void cry_array_append(struct CryArray* array, pointer data);
void cry_array_prepend(struct CryArray* array, pointer data);
void cry_array_insert(struct CryArray* array, pointer data);
int cry_array_remove(struct CryArray* array, size_t index);
void cry_array_append_range(struct CryArray* array, pointer data, size_t range);
void cry_array_prepend_range(struct CryArray* array, pointer data, size_t range);
void cry_array_insert_range(struct CryArray* array, pointer data, size_t range);
int cry_array_remove_range(struct CryArray* array, size_t index, size_t range);
pointer cry_array_get(struct CryArray* array, size_t index);
#endif // CRYSTAL_STRUCTURES_ARRAY_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment