Skip to content

Commit

Permalink
Merge pull request #20 from ryukinix/structs
Browse files Browse the repository at this point in the history
Expose data structures to header
  • Loading branch information
ryukinix committed Mar 17, 2019
2 parents b8f77c3 + ff6493c commit 983e323
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 41 deletions.
6 changes: 0 additions & 6 deletions src/circle/circle.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@
#include "circle.h"
#include "utils/check_alloc.h"

struct circle {
Point* center; /**< the center point of circle */
float radius; /**< the radius size of the circle */
};


Circle* circle_create(Point *center, float radius) {
Circle* c = (Circle *) malloc(sizeof(Circle));
check_alloc(c);
Expand Down
8 changes: 7 additions & 1 deletion src/circle/circle.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@
* Has the fields hidden by struct circle
* as (Point* center) and (float radius)
*/
typedef struct circle Circle;
struct Circle {
Point* center; /**< the center point of circle */
float radius; /**< the radius size of the circle */
};


typedef struct Circle Circle;

/**
* @brief allocate a new circle on memory based on its parameters
Expand Down
6 changes: 0 additions & 6 deletions src/list/circular/list-circular.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@
#include <stdlib.h>
#include <stdio.h>

struct listCircular {
int data;
struct listCircular *next;
};


ListCircular* list_circular__new_node(int data) {
ListCircular* node = (ListCircular*) malloc(sizeof(ListCircular));
node->data = data;
Expand Down
11 changes: 10 additions & 1 deletion src/list/circular/list-circular.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,18 @@

#ifndef LIST_CIRCULAR_H
#define LIST_CIRCULAR_H
/**
* @brief A List circular data structure.
* The last *next pointer points to the first.
*/
struct ListCircular {
int data;
struct ListCircular *next;
};


/** List circular alias */
typedef struct listCircular ListCircular;
typedef struct ListCircular ListCircular;

#define EMPTY_LIST_CIRCULAR (ListCircular*) 0

Expand Down
5 changes: 0 additions & 5 deletions src/list/double/list-double.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@
#include "list-double.h"
#include "utils/check_alloc.h"

struct listDouble {
int data;
struct listDouble *next;
struct listDouble *prev;
};

ListDouble* list_double__new_node(int data) {
ListDouble* node = (ListDouble*) malloc(sizeof(ListDouble));
Expand Down
11 changes: 10 additions & 1 deletion src/list/double/list-double.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,16 @@
#ifndef LIST_DOUBLE_H
#define LIST_DOUBLE_H

typedef struct listDouble ListDouble;
/**
* @brief Linked List with double pointers.
*/
struct ListDouble {
int data;
struct ListDouble *next;
struct ListDouble *prev;
};

typedef struct ListDouble ListDouble;

#define EMPTY_LIST_DOUBLE (ListDouble*) 0

Expand Down
6 changes: 3 additions & 3 deletions src/list/single/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
* Shared struct definition because we have multiple source files
* which need to know how the internal struct is implemented
*/
struct list_node {
struct ListNode {
int data;
struct list_node *next;
struct ListNode *next;
};

/** Public type List for Singly Linked Lists */
typedef struct list_node List;
typedef struct ListNode List;

#define EMPTY_LIST (List*) 0

Expand Down
5 changes: 0 additions & 5 deletions src/point/point.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@
#include "point.h"
#include "utils/check_alloc.h"

struct point {
float x;
float y;
};


Point* point_create(float x, float y) {
Point* p = (Point *) malloc(sizeof(Point));
Expand Down
10 changes: 8 additions & 2 deletions src/point/point.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@
#define POINT_H

/**
* @brief struct Point as 2D space pointer
* @brief struct Point as 2D space pointer.
*/
typedef struct point Point;
struct Point {
float x; /**< x horizontal point on 2D plane */
float y; /**< y vertical point on 2D plane */
};


typedef struct Point Point;

/**
* @brief create a new Point and set x an y
Expand Down
5 changes: 0 additions & 5 deletions src/pqueue/pqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@
#include <stdlib.h>
#include <stdio.h>

struct pqueue_t {
int heap[PQUEUE_SIZE];
int size;
};

void swap_values(int *e1, int *e2) {
int temp = *e1;
*e1 = *e2;
Expand Down
14 changes: 13 additions & 1 deletion src/pqueue/pqueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,19 @@

#define HEAP_EMPTY_CELL -1

typedef struct pqueue_t PQueue;
/**
* @brief Priority Queue Data Structure.
* Like a normal queue about push/pop logic,
* but each individual now heave a weight. A inner
* heap implementation it's provided.
*/
struct PQueue {
int heap[PQUEUE_SIZE]; /**< inner heap for weights */
int size; /**< the current size of PQueue */
};


typedef struct PQueue PQueue;

PQueue* pqueue_create();

Expand Down
8 changes: 4 additions & 4 deletions src/tree/binary-tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
#define TypeFormat "%d"
#endif

struct node {
struct BinaryNode {
Type value;
struct node* left;
struct node* right;
struct BinaryNode* left;
struct BinaryNode* right;
};

typedef struct node BinaryTree;
typedef struct BinaryNode BinaryTree;

#endif
2 changes: 1 addition & 1 deletion src/tree/bst/bst.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "tree/binary-tree.h"

/* Binary Search Tree DataType Definition */
typedef struct node BSTree;
typedef struct BinaryNode BSTree;

#define BST_EMPTY (BSTree*) 0

Expand Down

0 comments on commit 983e323

Please sign in to comment.