This repository has been archived by the owner on Oct 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from localytics/refactor
Allow NOT actions
- Loading branch information
Showing
18 changed files
with
358 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,39 @@ | ||
#ifndef COGITO_BUF | ||
#define COGITO_BUF | ||
#ifndef COGITO_BUFFER | ||
#define COGITO_BUFFER | ||
|
||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <unistd.h> | ||
|
||
typedef struct cg_buf { | ||
/** | ||
* A struct representing an expandable string. Contains the current length of | ||
* the string, the current capacity of the string, and a pointer to the string | ||
* itself. | ||
*/ | ||
typedef struct { | ||
size_t length; | ||
size_t capacity; | ||
char *content; | ||
} cg_buf_t; | ||
|
||
/** | ||
* Initialize and return a new cg_buf_t struct. | ||
* @return A newly allocated and initialized buffer struct | ||
*/ | ||
cg_buf_t* cg_buf_build(void); | ||
|
||
/** | ||
* Copy a given string onto the given buffer, expanding if necessary. | ||
* @param buffer The buffer on which to append | ||
* @param str The string to append onto the buffer | ||
* @return An integer describing success (0 for success, 1 for failure) | ||
*/ | ||
int cg_buf_append(cg_buf_t *buffer, const char *str); | ||
|
||
/** | ||
* Free the allocated buffer and its associated string. | ||
* @param buffer The buffer to free | ||
*/ | ||
void cg_buf_free(cg_buf_t *buffer); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,60 @@ | ||
#include "linked_list.h" | ||
|
||
// Append a node to the end of the list | ||
void cg_ll_append(cg_node_t *head, char *val) { | ||
cg_node_t *tail = cg_ll_build(val); | ||
cg_node_t *ptr = head; | ||
static cg_node_t* cg_ll_build_node(char *value) { | ||
cg_node_t *node = (cg_node_t *) malloc(sizeof(cg_node_t)); | ||
node->value = value; | ||
node->next = NULL; | ||
return node; | ||
} | ||
|
||
void cg_ll_append(cg_list_t *list, char *value) { | ||
cg_node_t *tail = cg_ll_build_node(value); | ||
cg_node_t *ptr = list->head; | ||
|
||
while(ptr->next != NULL) { | ||
ptr = ptr->next; | ||
} | ||
ptr->next = tail; | ||
} | ||
|
||
// Build the first node or append a node to the list | ||
cg_node_t* cg_ll_update(cg_node_t *head, char *val) { | ||
if (head == NULL) { | ||
return cg_ll_build(val); | ||
cg_list_t* cg_ll_update(cg_list_t *list, char *value) { | ||
if (list == NULL) { | ||
return cg_ll_build(value); | ||
} | ||
cg_ll_append(head, val); | ||
return head; | ||
cg_ll_append(list, value); | ||
return list; | ||
} | ||
|
||
// Build a list node | ||
cg_node_t* cg_ll_build(char *val) { | ||
cg_node_t *node = (cg_node_t*) malloc(sizeof(cg_node_t)); | ||
node->val = val; | ||
node->next = NULL; | ||
return node; | ||
} | ||
|
||
// Print out the list starting at the given node | ||
void cg_ll_print(cg_node_t *node) { | ||
cg_node_t *ptr; | ||
|
||
cg_ll_foreach(node, ptr) { | ||
printf("[%s]\n", ptr->val); | ||
} | ||
printf("\n"); | ||
cg_list_t* cg_ll_build(char *value) { | ||
cg_list_t *list = (cg_list_t *) malloc(sizeof(cg_list_t)); | ||
list->negated = 0; | ||
list->head = cg_ll_build_node(value); | ||
return list; | ||
} | ||
|
||
// The number of nodes in the list | ||
int cg_ll_size(cg_node_t *head) { | ||
int size = 0; | ||
size_t cg_ll_value_size_sum(cg_list_t *list) { | ||
size_t size = 0; | ||
cg_node_t *ptr; | ||
|
||
cg_ll_foreach(head, ptr) { | ||
size += 1; | ||
cg_ll_foreach(list, ptr) { | ||
size += strlen(ptr->value); | ||
} | ||
return size; | ||
} | ||
|
||
// The sum of the size of all of the values in the list | ||
size_t cg_ll_val_size_sum(cg_node_t *head) { | ||
size_t size = 0; | ||
cg_node_t *ptr; | ||
|
||
cg_ll_foreach(head, ptr) { | ||
size += strlen(ptr->val); | ||
} | ||
return size; | ||
void cg_ll_negate(cg_list_t *list) { | ||
list->negated = 1 - list->negated; | ||
} | ||
|
||
// Free the memory for the entire list | ||
void cg_ll_free(cg_node_t *head) { | ||
cg_node_t *previous = head; | ||
cg_node_t *current = head; | ||
void cg_ll_free(cg_list_t *list) { | ||
cg_node_t *previous = list->head; | ||
cg_node_t *current = list->head; | ||
|
||
while(current != NULL) { | ||
previous = current; | ||
current = current->next; | ||
free(previous); | ||
} | ||
|
||
free(list); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,74 @@ | ||
#ifndef COGITO_LL | ||
#define COGITO_LL | ||
#ifndef COGITO_LINKED_LIST | ||
#define COGITO_LINKED_LIST | ||
|
||
#include <ctype.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
/** | ||
* A struct representing a node in the list. Contains a pointer to a string | ||
* representing the AWS identifier and a pointer to the next node. | ||
*/ | ||
typedef struct cg_node { | ||
char *val; | ||
char *value; | ||
struct cg_node *next; | ||
} cg_node_t; | ||
|
||
#define cg_ll_foreach(head, ptr) \ | ||
for ((ptr) = head; (ptr) != NULL; (ptr) = (ptr)->next) | ||
/** | ||
* A struct representing the list. Contains a pointer to the head node of the | ||
* list and an integer flag representing whether or not this list is negated. | ||
*/ | ||
typedef struct { | ||
struct cg_node *head; | ||
int negated; | ||
} cg_list_t; | ||
|
||
void cg_ll_append(cg_node_t *head, char *val); | ||
cg_node_t* cg_ll_update(cg_node_t *head, char *val); | ||
cg_node_t* cg_ll_build(char *val); | ||
void cg_ll_print(cg_node_t *node); | ||
int cg_ll_size(cg_node_t *head); | ||
size_t cg_ll_val_size_sum(cg_node_t *head); | ||
void cg_ll_free(cg_node_t *head); | ||
/** | ||
* A macro for looping through the nodes in the list. | ||
*/ | ||
#define cg_ll_foreach(list, ptr) \ | ||
for ((ptr) = list->head; (ptr) != NULL; (ptr) = (ptr)->next) | ||
|
||
/** | ||
* Append a node to the end of the list. | ||
* @param list The list on which to append the new value | ||
* @param value The new value that should be appended to the list | ||
*/ | ||
void cg_ll_append(cg_list_t *list, char *value); | ||
|
||
/** | ||
* Build the first node or append a node to the list. | ||
* @param list The list that should be updated (or created if NULL) | ||
* @param value The new value that should be appended to the list | ||
* @return The newly created or updated list | ||
*/ | ||
cg_list_t* cg_ll_update(cg_list_t *list, char *value); | ||
|
||
/** | ||
* Build the first list node and return the list. | ||
* @param value The value to be used to create the first node | ||
* @return The newly created list | ||
*/ | ||
cg_list_t* cg_ll_build(char *value); | ||
|
||
/** | ||
* The sum of the size of all of the values in the list. | ||
* @param list The list to with which to compute the sum | ||
* @return The size_t representing the sum | ||
*/ | ||
size_t cg_ll_value_size_sum(cg_list_t *list); | ||
|
||
/** | ||
* Negate the given list. | ||
* @param list The list on which to flip the negated flag | ||
*/ | ||
void cg_ll_negate(cg_list_t *list); | ||
|
||
/** | ||
* Free the memory for the entire list. | ||
* @param list The list to free | ||
*/ | ||
void cg_ll_free(cg_list_t *list); | ||
|
||
#endif |
Oops, something went wrong.