normed: output directory

This commit is contained in:
maix0 2024-10-12 15:45:45 +02:00
parent 7bb95e24a6
commit 3d11b63428
37 changed files with 692 additions and 708 deletions

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */ /* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/06 11:00:22 by maiboyer #+# #+# */ /* Created: 2023/12/06 11:00:22 by maiboyer #+# #+# */
/* Updated: 2023/12/11 15:24:44 by maiboyer ### ########.fr */ /* Updated: 2024/10/12 15:40:37 by maiboyer ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -15,8 +15,6 @@
# define DEFAULT_BUCKETS 750 # define DEFAULT_BUCKETS 750
# include "me/hash/hasher.h" # include "me/hash/hasher.h"
# include "me/types.h" # include "me/types.h"
# include <stddef.h> # include <stddef.h>
@ -36,10 +34,9 @@ typedef struct s_kv_env
typedef void (*t_hash_env_fn)(t_hasher *hasher, t_str *key); typedef void (*t_hash_env_fn)(t_hasher *hasher, t_str *key);
/// @typedef A function that drops a key-value pair /// @typedef A function that drops a key-value pair
typedef void (*t_free_env_fn)(t_kv_env val); typedef void (*t_free_env_fn)(t_kv_env val);
/// @typedef A function that compares two keys and returns true if they are equal /// @typedef A function that compares two keys and returns true if they are eq
typedef bool (*t_eq_env_fn)(t_str *lhs, t_str *rhs); typedef bool (*t_eq_env_fn)(t_str *lhs, t_str *rhs);
/// @struct A single entry in the hashmap /// @struct A single entry in the hashmap
/// @var hash_id The hash of the key /// @var hash_id The hash of the key
/// @var kv The key-value pair /// @var kv The key-value pair
@ -68,20 +65,24 @@ typedef struct s_hashmap_env
t_free_env_fn free; t_free_env_fn free;
} t_hashmap_env; } t_hashmap_env;
/// @brief Creates a new hashmap with the given hash, comparison, and free functions /// @brief Creates a new hashmap with the given hash, comparison, and free
/// functions
/// @param hash The hash function /// @param hash The hash function
/// @param cmp The comparison function /// @param cmp The comparison function
/// @param free The free function /// @param free The free function
/// @return A new hashmap /// @return A new hashmap
t_hashmap_env *hmap_env_new(t_hash_env_fn hash, t_eq_env_fn cmp, t_free_env_fn free); t_hashmap_env *hmap_env_new(t_hash_env_fn hash, t_eq_env_fn cmp,
t_free_env_fn free);
/// @brief Creates a new hashmap with the given hash, comparison, and free functions /// @brief Creates a new hashmap with the given hash, comparison, and free
/// functions
/// @param hash The hash function /// @param hash The hash function
/// @param cmp The comparison function /// @param cmp The comparison function
/// @param free The free function /// @param free The free function
/// @param cap The number of buckets /// @param cap The number of buckets
/// @return A new hashmap /// @return A new hashmap
t_hashmap_env *hmap_env_new_with_buckets(t_hash_env_fn hash, t_eq_env_fn cmp, t_free_env_fn free, size_t cap); t_hashmap_env *hmap_env_new_with_buckets(t_hash_env_fn hash,
t_eq_env_fn cmp, t_free_env_fn free, size_t cap);
/// @brief Free the hashmap and all of its entries /// @brief Free the hashmap and all of its entries
/// @param hmap The hashmap to free /// @param hmap The hashmap to free
@ -96,12 +97,14 @@ void hmap_env_clear(t_hashmap_env *hmap);
/// @param key The key /// @param key The key
/// @param value The value /// @param value The value
/// @return true if the key already existed before, false otherwise /// @return true if the key already existed before, false otherwise
bool hmap_env_insert(t_hashmap_env *hmap, t_str key, t_str value); bool hmap_env_insert(t_hashmap_env *hmap, t_str key,
t_str value);
/// @brief Gets the value associated with the key /// @brief Gets the value associated with the key
/// @param hmap The hashmap /// @param hmap The hashmap
/// @param key The key /// @param key The key
/// @return The value associated with the key, or NULL if the key is not in the hashmap /// @return The value associated with the key, or NULL if the key is not in
/// the hashmap
t_str *hmap_env_get(t_hashmap_env *hmap, t_str *key); t_str *hmap_env_get(t_hashmap_env *hmap, t_str *key);
/// @brief Removes the key-value pair from the hashmap /// @brief Removes the key-value pair from the hashmap
@ -116,23 +119,30 @@ void hmap_env_remove(t_hashmap_env *hmap, t_str *key);
/// @param prev The previous entry in the bucket /// @param prev The previous entry in the bucket
/// @return The entry, or NULL if the key is not in the hashmap /// @return The entry, or NULL if the key is not in the hashmap
/// @note this is an internal function /// @note this is an internal function
t_entry_env *hmap_env_get_entry(t_hashmap_env *hmap, t_usize hash, t_str *key, t_entry_env **prev); t_entry_env *hmap_env_get_entry(t_hashmap_env *hmap, t_usize hash,
t_str *key, t_entry_env **prev);
/// @brief Iterates over the hashmap and calls the given function for each key-value pair /// @brief Iterates over the hashmap and calls the given function for each
/// key-value pair
/// @param self The hashmap /// @param self The hashmap
/// @param func The function to call /// @param func The function to call
/// @param ctx The context to pass to the function /// @param ctx The context to pass to the function
/// @return An error code /// @return An error code
/// @note The iteration can be stopped by returning an error code from the function /// @note The iteration can be stopped by returning an error code from the
t_error hmap_env_iter(t_hashmap_env *self, t_error (*func)(t_usize idx, const t_str *key, t_str *val, void *ctx), void *ctx); /// function
t_error hmap_env_iter(t_hashmap_env *self,
t_error (*func)(t_usize idx, const t_str *key,
t_str *val, void *ctx), void *ctx);
/// @brief Clone an entire hashmap, using the given function to duplicate
/// @brief Clone an entire hashmap, using the given function to duplicate the items /// the items
/// @param self The hashmap /// @param self The hashmap
/// @param func The function to call /// @param func The function to call
/// @param ctx The context to pass to the function /// @param ctx The context to pass to the function
/// @param out The cloned hashmap /// @param out The cloned hashmap
/// @return An error code /// @return An error code
t_error hmap_env_clone(t_hashmap_env *self, t_error (*clone)(const t_kv_env *val, void *ctx, t_kv_env *out), void *ctx, t_hashmap_env **out); t_error hmap_env_clone(t_hashmap_env *self,
t_error (*clone)(const t_kv_env *val, void *ctx,
t_kv_env *out), void *ctx, t_hashmap_env **out);
#endif #endif

View file

@ -0,0 +1,34 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* include_token_workaround.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/12 15:44:15 by maiboyer #+# #+# */
/* Updated: 2024/10/12 15:44:35 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef INCLUDE_TOKEN_WORKAROUND_H
# define INCLUDE_TOKEN_WORKAROUND_H
# include "me/types.h"
typedef struct s_token t_token;
/// @brief A function that free an t_token
typedef void (*t_free_token_item)(t_token elem);
/// @brief A dynamic array of t_token
typedef struct s_vec_token t_vec_token;
struct s_vec_token
{
t_free_token_item free_func;
t_usize len;
t_usize capacity;
t_token *buffer;
};
#endif /* INCLUDE_TOKEN_WORKAROUND_H */

View file

@ -17,7 +17,8 @@
# include "me/types.h" # include "me/types.h"
/// @brief A function that takes two t_ast_node and compare them /// @brief A function that takes two t_ast_node and compare them
typedef bool (*t_vec_ast_sort_fn)(t_ast_node *lhs, t_ast_node *rhs); typedef bool (*t_vec_ast_sort_fn)(t_ast_node *lhs,
t_ast_node *rhs);
/// @brief A function that free an t_ast_node /// @brief A function that free an t_ast_node
typedef void (*t_free_ast_item)(t_ast_node elem); typedef void (*t_free_ast_item)(t_ast_node elem);
@ -50,7 +51,8 @@ t_vec_ast vec_ast_new(t_usize capacity,
/// @brief Push an element to the last position of the vec_ast /// @brief Push an element to the last position of the vec_ast
/// @param vec The vec_ast to push the element to /// @param vec The vec_ast to push the element to
/// @param element The element to push /// @param element The element to push
t_error vec_ast_push(t_vec_ast *vec, t_ast_node element); t_error vec_ast_push(t_vec_ast *vec,
t_ast_node element);
/// @brief Push an element to the first position of the vec_ast /// @brief Push an element to the first position of the vec_ast
/// @param vec The vec_ast to push the element to /// @param vec The vec_ast to push the element to
@ -64,7 +66,8 @@ t_error vec_ast_push_front(t_vec_ast *vec,
/// @param vec The vec_ast to get the element from /// @param vec The vec_ast to get the element from
/// @param[out] out The last element of the vec_ast /// @param[out] out The last element of the vec_ast
/// @return true if the operation failed, false otherwise /// @return true if the operation failed, false otherwise
t_error vec_ast_pop(t_vec_ast *vec, t_ast_node *value); t_error vec_ast_pop(t_vec_ast *vec,
t_ast_node *value);
/// @brief Get the first element from the vec_ast, and remove it from /// @brief Get the first element from the vec_ast, and remove it from
/// the vec_ast /// the vec_ast
@ -72,7 +75,8 @@ t_error vec_ast_pop(t_vec_ast *vec, t_ast_node *value);
/// @param[out] out The first element of the vec_ast /// @param[out] out The first element of the vec_ast
/// @return true if the operation failed, false otherwise /// @return true if the operation failed, false otherwise
/// @note This operation is O(n) /// @note This operation is O(n)
t_error vec_ast_pop_front(t_vec_ast *vec, t_ast_node *value); t_error vec_ast_pop_front(t_vec_ast *vec,
t_ast_node *value);
/// @brief Free the vector and all its elements /// @brief Free the vector and all its elements
/// @param vec The vec_ast to free /// @param vec The vec_ast to free
@ -91,7 +95,8 @@ t_error vec_ast_reserve(t_vec_ast *vec,
/// @param fn The function to run on each element /// @param fn The function to run on each element
/// @param[out] index The index of the first element that returns true /// @param[out] index The index of the first element that returns true
t_error vec_ast_find(t_vec_ast *vec, t_error vec_ast_find(t_vec_ast *vec,
bool (*fn)(const t_ast_node *), t_usize *index); bool (*fn)(const t_ast_node *),
t_usize *index);
/// @brief Run the function and returns the index of the first element that /// @brief Run the function and returns the index of the first element that
/// returns true, but starting at index starting_index /// returns true, but starting at index starting_index
@ -111,7 +116,8 @@ t_error vec_ast_find_starting(t_vec_ast *vec,
/// @return true if the operation failed, false otherwise /// @return true if the operation failed, false otherwise
/// @note If the vec_ast is empty, result will be true /// @note If the vec_ast is empty, result will be true
t_error vec_ast_all(t_vec_ast *vec, t_error vec_ast_all(t_vec_ast *vec,
bool (*fn)(const t_ast_node *), bool *result); bool (*fn)(const t_ast_node *),
bool *result);
/// @brief Run the function on every element of the vec_ast and returns /// @brief Run the function on every element of the vec_ast and returns
/// if any element returned true /// if any element returned true
@ -121,15 +127,16 @@ t_error vec_ast_all(t_vec_ast *vec,
/// @return true if the operation failed, false otherwise /// @return true if the operation failed, false otherwise
/// @note If the vec_ast is empty, result will be false /// @note If the vec_ast is empty, result will be false
t_error vec_ast_any(t_vec_ast *vec, t_error vec_ast_any(t_vec_ast *vec,
bool (*fn)(const t_ast_node *), bool *result); bool (*fn)(const t_ast_node *),
bool *result);
/// @brief Run the function on every element of the vec_ast /// @brief Run the function on every element of the vec_ast
/// @param vec The vec_ast to iterate over /// @param vec The vec_ast to iterate over
/// @param fn The function to run on each element /// @param fn The function to run on each element
/// @param state The state to pass to the function /// @param state The state to pass to the function
void vec_ast_iter(t_vec_ast *vec, void vec_ast_iter(t_vec_ast *vec,
void (*fn)(t_usize index, t_ast_node *value, void (*fn)(t_usize index,
void *state), t_ast_node *value, void *state),
void *state); void *state);
/// @brief Reverse the order of the elements in the vec_ast /// @brief Reverse the order of the elements in the vec_ast
@ -146,7 +153,8 @@ void vec_ast_sort(t_vec_ast *vec,
/// @param vec The vec_ast to get the element from /// @param vec The vec_ast to get the element from
/// @param[out] out A pointer to the last element of the vec_ast /// @param[out] out A pointer to the last element of the vec_ast
/// @return true if the operation failed, false otherwise /// @return true if the operation failed, false otherwise
t_error vec_ast_back(t_vec_ast *vec, t_ast_node **out); t_error vec_ast_back(t_vec_ast *vec,
t_ast_node **out);
/// @brief Get a pointer to the i'th element, or NULL otherwise /// @brief Get a pointer to the i'th element, or NULL otherwise
/// @param vec The vec_ast to get the element from /// @param vec The vec_ast to get the element from
@ -161,14 +169,15 @@ t_ast_node *vec_ast_last(t_vec_ast *vec);
/// @brief Perform a simple bytewise copy into the other vector /// @brief Perform a simple bytewise copy into the other vector
/// @param vec The vec_ast to be copied from /// @param vec The vec_ast to be copied from
/// @param dest The vec_ast to be copied to /// @param dest The vec_ast to be copied to
void vec_ast_copy_into(t_vec_ast *vec, t_vec_ast *dest); void vec_ast_copy_into(t_vec_ast *vec,
t_vec_ast *dest);
/// read code lol /// read code lol
void vec_ast_splice(t_vec_ast *self, void vec_ast_splice(t_vec_ast *self,
struct s_vec_ast_splice_arguments args); struct s_vec_ast_splice_arguments args);
struct s_vec_ast_splice_arguments vec_ast_splice_args( struct s_vec_ast_splice_arguments vec_ast_splice_args(t_usize index,
t_usize index, t_usize old_count, t_usize new_count, t_usize old_count, t_usize new_count,
const t_ast_node *elements); const t_ast_node *elements);
#endif #endif

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */ /* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/04 18:46:53 by maiboyer #+# #+# */ /* Created: 2023/12/04 18:46:53 by maiboyer #+# #+# */
/* Updated: 2023/12/09 17:53:00 by maiboyer ### ########.fr */ /* Updated: 2024/10/12 15:43:26 by maiboyer ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -17,7 +17,8 @@
# include "me/types.h" # include "me/types.h"
/// @brief A function that takes two t_expandable_str and compare them /// @brief A function that takes two t_expandable_str and compare them
typedef bool (*t_vec_estr_sort_fn)(t_expandable_str *lhs, t_expandable_str *rhs); typedef bool (*t_vec_estr_sort_fn)(t_expandable_str *lhs,
t_expandable_str *rhs);
/// @brief A function that free an t_expandable_str /// @brief A function that free an t_expandable_str
typedef void (*t_free_estr_item)(t_expandable_str elem); typedef void (*t_free_estr_item)(t_expandable_str elem);
@ -50,7 +51,8 @@ t_vec_estr vec_estr_new(t_usize capacity,
/// @brief Push an element to the last position of the vec_estr /// @brief Push an element to the last position of the vec_estr
/// @param vec The vec_estr to push the element to /// @param vec The vec_estr to push the element to
/// @param element The element to push /// @param element The element to push
t_error vec_estr_push(t_vec_estr *vec, t_expandable_str element); t_error vec_estr_push(t_vec_estr *vec,
t_expandable_str element);
/// @brief Push an element to the first position of the vec_estr /// @brief Push an element to the first position of the vec_estr
/// @param vec The vec_estr to push the element to /// @param vec The vec_estr to push the element to
@ -64,7 +66,8 @@ t_error vec_estr_push_front(t_vec_estr *vec,
/// @param vec The vec_estr to get the element from /// @param vec The vec_estr to get the element from
/// @param[out] out The last element of the vec_estr /// @param[out] out The last element of the vec_estr
/// @return true if the operation failed, false otherwise /// @return true if the operation failed, false otherwise
t_error vec_estr_pop(t_vec_estr *vec, t_expandable_str *value); t_error vec_estr_pop(t_vec_estr *vec,
t_expandable_str *value);
/// @brief Get the first element from the vec_estr, and remove it from /// @brief Get the first element from the vec_estr, and remove it from
/// the vec_estr /// the vec_estr
@ -72,7 +75,8 @@ t_error vec_estr_pop(t_vec_estr *vec, t_expandable_str *value);
/// @param[out] out The first element of the vec_estr /// @param[out] out The first element of the vec_estr
/// @return true if the operation failed, false otherwise /// @return true if the operation failed, false otherwise
/// @note This operation is O(n) /// @note This operation is O(n)
t_error vec_estr_pop_front(t_vec_estr *vec, t_expandable_str *value); t_error vec_estr_pop_front(t_vec_estr *vec,
t_expandable_str *value);
/// @brief Free the vector and all its elements /// @brief Free the vector and all its elements
/// @param vec The vec_estr to free /// @param vec The vec_estr to free
@ -91,7 +95,8 @@ t_error vec_estr_reserve(t_vec_estr *vec,
/// @param fn The function to run on each element /// @param fn The function to run on each element
/// @param[out] index The index of the first element that returns true /// @param[out] index The index of the first element that returns true
t_error vec_estr_find(t_vec_estr *vec, t_error vec_estr_find(t_vec_estr *vec,
bool (*fn)(const t_expandable_str *), t_usize *index); bool (*fn)(const t_expandable_str *),
t_usize *index);
/// @brief Run the function and returns the index of the first element that /// @brief Run the function and returns the index of the first element that
/// returns true, but starting at index starting_index /// returns true, but starting at index starting_index
@ -111,7 +116,8 @@ t_error vec_estr_find_starting(t_vec_estr *vec,
/// @return true if the operation failed, false otherwise /// @return true if the operation failed, false otherwise
/// @note If the vec_estr is empty, result will be true /// @note If the vec_estr is empty, result will be true
t_error vec_estr_all(t_vec_estr *vec, t_error vec_estr_all(t_vec_estr *vec,
bool (*fn)(const t_expandable_str *), bool *result); bool (*fn)(const t_expandable_str *),
bool *result);
/// @brief Run the function on every element of the vec_estr and returns /// @brief Run the function on every element of the vec_estr and returns
/// if any element returned true /// if any element returned true
@ -121,16 +127,17 @@ t_error vec_estr_all(t_vec_estr *vec,
/// @return true if the operation failed, false otherwise /// @return true if the operation failed, false otherwise
/// @note If the vec_estr is empty, result will be false /// @note If the vec_estr is empty, result will be false
t_error vec_estr_any(t_vec_estr *vec, t_error vec_estr_any(t_vec_estr *vec,
bool (*fn)(const t_expandable_str *), bool *result); bool (*fn)(const t_expandable_str *),
bool *result);
/// @brief Run the function on every element of the vec_estr /// @brief Run the function on every element of the vec_estr
/// @param vec The vec_estr to iterate over /// @param vec The vec_estr to iterate over
/// @param fn The function to run on each element /// @param fn The function to run on each element
/// @param state The state to pass to the function /// @param state The state to pass to the function
void vec_estr_iter(t_vec_estr *vec, void vec_estr_iter(t_vec_estr *vec,
void (*fn)(t_usize index, t_expandable_str *value, void (*fn)(t_usize index,
void *state), t_expandable_str *value,
void *state); void *state), void *state);
/// @brief Reverse the order of the elements in the vec_estr /// @brief Reverse the order of the elements in the vec_estr
/// @param vec The vec_estr to reverse /// @param vec The vec_estr to reverse
@ -146,7 +153,8 @@ void vec_estr_sort(t_vec_estr *vec,
/// @param vec The vec_estr to get the element from /// @param vec The vec_estr to get the element from
/// @param[out] out A pointer to the last element of the vec_estr /// @param[out] out A pointer to the last element of the vec_estr
/// @return true if the operation failed, false otherwise /// @return true if the operation failed, false otherwise
t_error vec_estr_back(t_vec_estr *vec, t_expandable_str **out); t_error vec_estr_back(t_vec_estr *vec,
t_expandable_str **out);
/// @brief Get a pointer to the i'th element, or NULL otherwise /// @brief Get a pointer to the i'th element, or NULL otherwise
/// @param vec The vec_estr to get the element from /// @param vec The vec_estr to get the element from
@ -161,14 +169,7 @@ t_expandable_str *vec_estr_last(t_vec_estr *vec);
/// @brief Perform a simple bytewise copy into the other vector /// @brief Perform a simple bytewise copy into the other vector
/// @param vec The vec_estr to be copied from /// @param vec The vec_estr to be copied from
/// @param dest The vec_estr to be copied to /// @param dest The vec_estr to be copied to
void vec_estr_copy_into(t_vec_estr *vec, t_vec_estr *dest); void vec_estr_copy_into(t_vec_estr *vec,
t_vec_estr *dest);
/// read code lol
void vec_estr_splice(t_vec_estr *self,
struct s_vec_estr_splice_arguments args);
struct s_vec_estr_splice_arguments vec_estr_splice_args(
t_usize index, t_usize old_count, t_usize new_count,
const t_expandable_str *elements);
#endif #endif

View file

@ -17,7 +17,8 @@
# include "me/types.h" # include "me/types.h"
/// @brief A function that takes two t_pid and compare them /// @brief A function that takes two t_pid and compare them
typedef bool (*t_vec_pid_sort_fn)(t_pid *lhs, t_pid *rhs); typedef bool (*t_vec_pid_sort_fn)(t_pid *lhs,
t_pid *rhs);
/// @brief A function that free an t_pid /// @brief A function that free an t_pid
typedef void (*t_free_pid_item)(t_pid elem); typedef void (*t_free_pid_item)(t_pid elem);
@ -72,7 +73,8 @@ t_error vec_pid_pop(t_vec_pid *vec, t_pid *value);
/// @param[out] out The first element of the vec_pid /// @param[out] out The first element of the vec_pid
/// @return true if the operation failed, false otherwise /// @return true if the operation failed, false otherwise
/// @note This operation is O(n) /// @note This operation is O(n)
t_error vec_pid_pop_front(t_vec_pid *vec, t_pid *value); t_error vec_pid_pop_front(t_vec_pid *vec,
t_pid *value);
/// @brief Free the vector and all its elements /// @brief Free the vector and all its elements
/// @param vec The vec_pid to free /// @param vec The vec_pid to free
@ -91,7 +93,8 @@ t_error vec_pid_reserve(t_vec_pid *vec,
/// @param fn The function to run on each element /// @param fn The function to run on each element
/// @param[out] index The index of the first element that returns true /// @param[out] index The index of the first element that returns true
t_error vec_pid_find(t_vec_pid *vec, t_error vec_pid_find(t_vec_pid *vec,
bool (*fn)(const t_pid *), t_usize *index); bool (*fn)(const t_pid *),
t_usize *index);
/// @brief Run the function and returns the index of the first element that /// @brief Run the function and returns the index of the first element that
/// returns true, but starting at index starting_index /// returns true, but starting at index starting_index
@ -111,7 +114,8 @@ t_error vec_pid_find_starting(t_vec_pid *vec,
/// @return true if the operation failed, false otherwise /// @return true if the operation failed, false otherwise
/// @note If the vec_pid is empty, result will be true /// @note If the vec_pid is empty, result will be true
t_error vec_pid_all(t_vec_pid *vec, t_error vec_pid_all(t_vec_pid *vec,
bool (*fn)(const t_pid *), bool *result); bool (*fn)(const t_pid *),
bool *result);
/// @brief Run the function on every element of the vec_pid and returns /// @brief Run the function on every element of the vec_pid and returns
/// if any element returned true /// if any element returned true
@ -121,7 +125,8 @@ t_error vec_pid_all(t_vec_pid *vec,
/// @return true if the operation failed, false otherwise /// @return true if the operation failed, false otherwise
/// @note If the vec_pid is empty, result will be false /// @note If the vec_pid is empty, result will be false
t_error vec_pid_any(t_vec_pid *vec, t_error vec_pid_any(t_vec_pid *vec,
bool (*fn)(const t_pid *), bool *result); bool (*fn)(const t_pid *),
bool *result);
/// @brief Run the function on every element of the vec_pid /// @brief Run the function on every element of the vec_pid
/// @param vec The vec_pid to iterate over /// @param vec The vec_pid to iterate over
@ -129,8 +134,7 @@ t_error vec_pid_any(t_vec_pid *vec,
/// @param state The state to pass to the function /// @param state The state to pass to the function
void vec_pid_iter(t_vec_pid *vec, void vec_pid_iter(t_vec_pid *vec,
void (*fn)(t_usize index, t_pid *value, void (*fn)(t_usize index, t_pid *value,
void *state), void *state), void *state);
void *state);
/// @brief Reverse the order of the elements in the vec_pid /// @brief Reverse the order of the elements in the vec_pid
/// @param vec The vec_pid to reverse /// @param vec The vec_pid to reverse
@ -161,14 +165,15 @@ t_pid *vec_pid_last(t_vec_pid *vec);
/// @brief Perform a simple bytewise copy into the other vector /// @brief Perform a simple bytewise copy into the other vector
/// @param vec The vec_pid to be copied from /// @param vec The vec_pid to be copied from
/// @param dest The vec_pid to be copied to /// @param dest The vec_pid to be copied to
void vec_pid_copy_into(t_vec_pid *vec, t_vec_pid *dest); void vec_pid_copy_into(t_vec_pid *vec,
t_vec_pid *dest);
/// read code lol /// read code lol
void vec_pid_splice(t_vec_pid *self, void vec_pid_splice(t_vec_pid *self,
struct s_vec_pid_splice_arguments args); struct s_vec_pid_splice_arguments args);
struct s_vec_pid_splice_arguments vec_pid_splice_args( struct s_vec_pid_splice_arguments vec_pid_splice_args(t_usize index,
t_usize index, t_usize old_count, t_usize new_count, t_usize old_count, t_usize new_count,
const t_pid *elements); const t_pid *elements);
#endif #endif

View file

@ -13,11 +13,11 @@
#ifndef VEC_STR_H #ifndef VEC_STR_H
# define VEC_STR_H # define VEC_STR_H
# include "me/types.h" # include "me/types.h"
/// @brief A function that takes two t_str and compare them /// @brief A function that takes two t_str and compare them
typedef bool (*t_vec_str_sort_fn)(t_str *lhs, t_str *rhs); typedef bool (*t_vec_str_sort_fn)(t_str *lhs,
t_str *rhs);
/// @brief A function that free an t_str /// @brief A function that free an t_str
typedef void (*t_free_str_item)(t_str elem); typedef void (*t_free_str_item)(t_str elem);
@ -72,7 +72,8 @@ t_error vec_str_pop(t_vec_str *vec, t_str *value);
/// @param[out] out The first element of the vec_str /// @param[out] out The first element of the vec_str
/// @return true if the operation failed, false otherwise /// @return true if the operation failed, false otherwise
/// @note This operation is O(n) /// @note This operation is O(n)
t_error vec_str_pop_front(t_vec_str *vec, t_str *value); t_error vec_str_pop_front(t_vec_str *vec,
t_str *value);
/// @brief Free the vector and all its elements /// @brief Free the vector and all its elements
/// @param vec The vec_str to free /// @param vec The vec_str to free
@ -91,7 +92,8 @@ t_error vec_str_reserve(t_vec_str *vec,
/// @param fn The function to run on each element /// @param fn The function to run on each element
/// @param[out] index The index of the first element that returns true /// @param[out] index The index of the first element that returns true
t_error vec_str_find(t_vec_str *vec, t_error vec_str_find(t_vec_str *vec,
bool (*fn)(const t_str *), t_usize *index); bool (*fn)(const t_str *),
t_usize *index);
/// @brief Run the function and returns the index of the first element that /// @brief Run the function and returns the index of the first element that
/// returns true, but starting at index starting_index /// returns true, but starting at index starting_index
@ -111,7 +113,8 @@ t_error vec_str_find_starting(t_vec_str *vec,
/// @return true if the operation failed, false otherwise /// @return true if the operation failed, false otherwise
/// @note If the vec_str is empty, result will be true /// @note If the vec_str is empty, result will be true
t_error vec_str_all(t_vec_str *vec, t_error vec_str_all(t_vec_str *vec,
bool (*fn)(const t_str *), bool *result); bool (*fn)(const t_str *),
bool *result);
/// @brief Run the function on every element of the vec_str and returns /// @brief Run the function on every element of the vec_str and returns
/// if any element returned true /// if any element returned true
@ -121,7 +124,8 @@ t_error vec_str_all(t_vec_str *vec,
/// @return true if the operation failed, false otherwise /// @return true if the operation failed, false otherwise
/// @note If the vec_str is empty, result will be false /// @note If the vec_str is empty, result will be false
t_error vec_str_any(t_vec_str *vec, t_error vec_str_any(t_vec_str *vec,
bool (*fn)(const t_str *), bool *result); bool (*fn)(const t_str *),
bool *result);
/// @brief Run the function on every element of the vec_str /// @brief Run the function on every element of the vec_str
/// @param vec The vec_str to iterate over /// @param vec The vec_str to iterate over
@ -129,8 +133,7 @@ t_error vec_str_any(t_vec_str *vec,
/// @param state The state to pass to the function /// @param state The state to pass to the function
void vec_str_iter(t_vec_str *vec, void vec_str_iter(t_vec_str *vec,
void (*fn)(t_usize index, t_str *value, void (*fn)(t_usize index, t_str *value,
void *state), void *state), void *state);
void *state);
/// @brief Reverse the order of the elements in the vec_str /// @brief Reverse the order of the elements in the vec_str
/// @param vec The vec_str to reverse /// @param vec The vec_str to reverse
@ -161,14 +164,15 @@ t_str *vec_str_last(t_vec_str *vec);
/// @brief Perform a simple bytewise copy into the other vector /// @brief Perform a simple bytewise copy into the other vector
/// @param vec The vec_str to be copied from /// @param vec The vec_str to be copied from
/// @param dest The vec_str to be copied to /// @param dest The vec_str to be copied to
void vec_str_copy_into(t_vec_str *vec, t_vec_str *dest); void vec_str_copy_into(t_vec_str *vec,
t_vec_str *dest);
/// read code lol /// read code lol
void vec_str_splice(t_vec_str *self, void vec_str_splice(t_vec_str *self,
struct s_vec_str_splice_arguments args); struct s_vec_str_splice_arguments args);
struct s_vec_str_splice_arguments vec_str_splice_args( struct s_vec_str_splice_arguments vec_str_splice_args(t_usize index,
t_usize index, t_usize old_count, t_usize new_count, t_usize old_count, t_usize new_count,
const t_str *elements); const t_str *elements);
#endif #endif

View file

@ -6,31 +6,14 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */ /* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/04 18:46:53 by maiboyer #+# #+# */ /* Created: 2023/12/04 18:46:53 by maiboyer #+# #+# */
/* Updated: 2024/09/26 18:29:43 by maiboyer ### ########.fr */ /* Updated: 2024/10/12 15:43:58 by maiboyer ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#ifndef VEC_TOKEN_H #ifndef VEC_TOKEN_H
# define VEC_TOKEN_H # define VEC_TOKEN_H
typedef struct s_token t_token; # include "./include_token_workaround.h"
#include "me/types.h"
/// @brief A function that free an t_token
typedef void (*t_free_token_item)(t_token elem);
/// @brief A dynamic array of t_token
typedef struct s_vec_token t_vec_token;
struct s_vec_token
{
t_free_token_item free_func;
t_usize len;
t_usize capacity;
t_token *buffer;
};
# ifndef TOKEN_H # ifndef TOKEN_H
# include "parser/token.h" # include "parser/token.h"
# endif # endif
@ -42,7 +25,8 @@ typedef bool (*t_vec_token_sort_fn)(t_token *lhs, t_token *rhs);
/// elements) /// elements)
/// @param free_function The function that will be used to free the elements of /// @param free_function The function that will be used to free the elements of
/// the vec_token /// the vec_token
t_vec_token vec_token_new(t_usize capacity, t_free_token_item free_function); t_vec_token vec_token_new(t_usize capacity,
t_free_token_item free_function);
/// @brief Push an element to the last position of the vec_token /// @brief Push an element to the last position of the vec_token
/// @param vec The vec_token to push the element to /// @param vec The vec_token to push the element to
/// @param element The element to push /// @param element The element to push
@ -52,7 +36,8 @@ t_error vec_token_push(t_vec_token *vec, t_token element);
/// @param vec The vec_token to push the element to /// @param vec The vec_token to push the element to
/// @param element The element to push /// @param element The element to push
/// @note This operation is O(n) /// @note This operation is O(n)
t_error vec_token_push_front(t_vec_token *vec, t_token element); t_error vec_token_push_front(t_vec_token *vec,
t_token element);
/// @brief Get the last element from the vec_token, and remove it from the /// @brief Get the last element from the vec_token, and remove it from the
/// vec_token /// vec_token
@ -67,7 +52,8 @@ t_error vec_token_pop(t_vec_token *vec, t_token *value);
/// @param[out] out The first element of the vec_token /// @param[out] out The first element of the vec_token
/// @return true if the operation failed, false otherwise /// @return true if the operation failed, false otherwise
/// @note This operation is O(n) /// @note This operation is O(n)
t_error vec_token_pop_front(t_vec_token *vec, t_token *value); t_error vec_token_pop_front(t_vec_token *vec,
t_token *value);
/// @brief Free the vector and all its elements /// @brief Free the vector and all its elements
/// @param vec The vec_token to free /// @param vec The vec_token to free
@ -77,14 +63,16 @@ void vec_token_free(t_vec_token vec);
/// @param vec The vec_token to reserve /// @param vec The vec_token to reserve
/// @param wanted_capacity The minimum capacity to reserve /// @param wanted_capacity The minimum capacity to reserve
/// @return true if the operation failed, false otherwise /// @return true if the operation failed, false otherwise
t_error vec_token_reserve(t_vec_token *vec, t_usize wanted_capacity); t_error vec_token_reserve(t_vec_token *vec,
t_usize wanted_capacity);
/// @brief Run the function and returns the index of the first element that /// @brief Run the function and returns the index of the first element that
/// returns true /// returns true
/// @param vec The vec_token to search in /// @param vec The vec_token to search in
/// @param fn The function to run on each element /// @param fn The function to run on each element
/// @param[out] index The index of the first element that returns true /// @param[out] index The index of the first element that returns true
t_error vec_token_find(t_vec_token *vec, bool (*fn)(const t_token *), t_usize *index); t_error vec_token_find(t_vec_token *vec,
bool (*fn)(const t_token *), t_usize *index);
/// @brief Run the function and returns the index of the first element that /// @brief Run the function and returns the index of the first element that
/// returns true, but starting at index starting_index /// returns true, but starting at index starting_index
@ -92,7 +80,9 @@ t_error vec_token_find(t_vec_token *vec, bool (*fn)(const t_token *), t_usize *i
/// @param fn The function to run on each element /// @param fn The function to run on each element
/// @param starting_index The index to start the search from /// @param starting_index The index to start the search from
/// @param[out] index The index of the first element that returns true /// @param[out] index The index of the first element that returns true
t_error vec_token_find_starting(t_vec_token *vec, bool (*fn)(const t_token *), t_usize starting_index, t_usize *index); t_error vec_token_find_starting(t_vec_token *vec,
bool (*fn)(const t_token *),
t_usize starting_index, t_usize *index);
/// @brief Run the function on every element of the vec_token and returns /// @brief Run the function on every element of the vec_token and returns
/// if all elements returned true /// if all elements returned true
@ -101,7 +91,8 @@ t_error vec_token_find_starting(t_vec_token *vec, bool (*fn)(const t_token *), t
/// @param[out] result The result of the operation /// @param[out] result The result of the operation
/// @return true if the operation failed, false otherwise /// @return true if the operation failed, false otherwise
/// @note If the vec_token is empty, result will be true /// @note If the vec_token is empty, result will be true
t_error vec_token_all(t_vec_token *vec, bool (*fn)(const t_token *), bool *result); t_error vec_token_all(t_vec_token *vec,
bool (*fn)(const t_token *), bool *result);
/// @brief Run the function on every element of the vec_token and returns /// @brief Run the function on every element of the vec_token and returns
/// if any element returned true /// if any element returned true
@ -110,13 +101,16 @@ t_error vec_token_all(t_vec_token *vec, bool (*fn)(const t_token *), bool *resul
/// @param[out] result The result of the operation /// @param[out] result The result of the operation
/// @return true if the operation failed, false otherwise /// @return true if the operation failed, false otherwise
/// @note If the vec_token is empty, result will be false /// @note If the vec_token is empty, result will be false
t_error vec_token_any(t_vec_token *vec, bool (*fn)(const t_token *), bool *result); t_error vec_token_any(t_vec_token *vec,
bool (*fn)(const t_token *), bool *result);
/// @brief Run the function on every element of the vec_token /// @brief Run the function on every element of the vec_token
/// @param vec The vec_token to iterate over /// @param vec The vec_token to iterate over
/// @param fn The function to run on each element /// @param fn The function to run on each element
/// @param state The state to pass to the function /// @param state The state to pass to the function
void vec_token_iter(t_vec_token *vec, void (*fn)(t_usize index, t_token *value, void *state), void *state); void vec_token_iter(t_vec_token *vec,
void (*fn)(t_usize index, t_token *value,
void *state), void *state);
/// @brief Reverse the order of the elements in the vec_token /// @brief Reverse the order of the elements in the vec_token
/// @param vec The vec_token to reverse /// @param vec The vec_token to reverse
@ -125,7 +119,8 @@ void vec_token_reverse(t_vec_token *vec);
/// @brief Sort the elements of the vec_token /// @brief Sort the elements of the vec_token
/// @param vec The vec_token to sort /// @param vec The vec_token to sort
/// @param is_sorted The function to use to compare the elements /// @param is_sorted The function to use to compare the elements
void vec_token_sort(t_vec_token *vec, t_vec_token_sort_fn is_sorted); void vec_token_sort(t_vec_token *vec,
t_vec_token_sort_fn is_sorted);
/// @brief Get a pointer to the last element of the vec_token /// @brief Get a pointer to the last element of the vec_token
/// @param vec The vec_token to get the element from /// @param vec The vec_token to get the element from
@ -146,6 +141,7 @@ t_token *vec_token_last(t_vec_token *vec);
/// @brief Perform a simple bytewise copy into the other vector /// @brief Perform a simple bytewise copy into the other vector
/// @param vec The vec_token to be copied from /// @param vec The vec_token to be copied from
/// @param dest The vec_token to be copied to /// @param dest The vec_token to be copied to
void vec_token_copy_into(t_vec_token *vec, t_vec_token *dest); void vec_token_copy_into(t_vec_token *vec,
t_vec_token *dest);
#endif #endif

View file

@ -1,12 +1,12 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* hashmap_env.c :+: :+: :+: */ /* env.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */ /* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/06 10:58:20 by maiboyer #+# #+# */ /* Created: 2023/12/06 10:58:20 by maiboyer #+# #+# */
/* Updated: 2023/12/11 15:32:51 by maiboyer ### ########.fr */ /* Updated: 2024/10/12 15:43:01 by maiboyer ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -17,17 +17,14 @@
#include "me/types.h" #include "me/types.h"
#include <stdlib.h> #include <stdlib.h>
t_hashmap_env *hmap_env_new(t_hash_env_fn hfunc, t_hashmap_env *hmap_env_new(t_hash_env_fn hfunc, t_eq_env_fn cfunc,
t_eq_env_fn cfunc,
t_free_env_fn free) t_free_env_fn free)
{ {
return ( return (hmap_env_new_with_buckets(hfunc, cfunc, free, DEFAULT_BUCKETS));
hmap_env_new_with_buckets(hfunc, cfunc, free, DEFAULT_BUCKETS));
} }
t_hashmap_env *hmap_env_new_with_buckets( t_hashmap_env *hmap_env_new_with_buckets(t_hash_env_fn hfunc,
t_hash_env_fn hfunc, t_eq_env_fn cfunc, t_eq_env_fn cfunc, t_free_env_fn free, t_usize buckets)
t_free_env_fn free, t_usize buckets)
{ {
t_hashmap_env *hmap; t_hashmap_env *hmap;
@ -69,10 +66,8 @@ void hmap_env_free(t_hashmap_env *hmap)
mem_free(hmap); mem_free(hmap);
} }
t_entry_env *hmap_env_get_entry(t_hashmap_env *hmap, t_entry_env *hmap_env_get_entry(t_hashmap_env *hmap, t_usize hashed_key,
t_usize hashed_key, t_str *key, t_entry_env **prev)
t_str *key,
t_entry_env **prev)
{ {
t_entry_env *entry; t_entry_env *entry;
@ -92,8 +87,7 @@ t_entry_env *hmap_env_get_entry(t_hashmap_env *hmap,
return (NULL); return (NULL);
} }
bool hmap_env_insert(t_hashmap_env *hmap, t_str key, bool hmap_env_insert(t_hashmap_env *hmap, t_str key, t_str value)
t_str value)
{ {
t_usize hashed_key; t_usize hashed_key;
t_entry_env *prev; t_entry_env *prev;
@ -117,9 +111,7 @@ bool hmap_env_insert(t_hashmap_env *hmap, t_str key,
} }
else else
{ {
hmap->free(entry->kv); entry->kv.key = (hmap->free(entry->kv), key);
entry->kv.key = key; return (entry->kv.val = value, true);
entry->kv.val = value;
return (true);
} }
} }

View file

@ -10,13 +10,9 @@
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "me/types.h"
#include "me/hashmap/hashmap_env.h" #include "me/hashmap/hashmap_env.h"
#include "me/mem/mem.h" #include "me/mem/mem.h"
#include "me/types.h"
void hmap_env_clear(t_hashmap_env *self) void hmap_env_clear(t_hashmap_env *self)
{ {

View file

@ -10,16 +10,12 @@
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "me/types.h"
#include "me/hashmap/hashmap_env.h" #include "me/hashmap/hashmap_env.h"
#include "me/types.h"
t_error hmap_env_clone(t_hashmap_env *self, t_error hmap_env_clone(t_hashmap_env *self,
t_error (*clone)(const t_kv_env *val, void *ctx, t_kv_env *out), t_error (*clone)(const t_kv_env *val, void *ctx, t_kv_env *out),
void *ctx, void *ctx, t_hashmap_env **out)
t_hashmap_env **out)
{ {
t_usize bucket_id; t_usize bucket_id;
t_entry_env *cur; t_entry_env *cur;
@ -27,7 +23,8 @@ t_error hmap_env_clone(t_hashmap_env *self,
t_hashmap_env *ret; t_hashmap_env *ret;
bucket_id = 0; bucket_id = 0;
ret = hmap_env_new_with_buckets(self->hfunc, self->cfunc, self->free, self->num_buckets); ret = hmap_env_new_with_buckets(self->hfunc, self->cfunc, self->free,
self->num_buckets);
if (ret == NULL) if (ret == NULL)
return (ERROR); return (ERROR);
while (bucket_id < self->num_buckets) while (bucket_id < self->num_buckets)

View file

@ -12,11 +12,8 @@
#include "me/hashmap/hashmap_env.h" #include "me/hashmap/hashmap_env.h"
t_error hmap_env_iter(t_hashmap_env *self, t_error hmap_env_iter(t_hashmap_env *self, t_error (*func)(t_usize idx,
t_error (*func)(t_usize idx, const t_str *key, t_str *val, void *ctx), void *ctx)
const t_str *key,
t_str *val, void *ctx),
void *ctx)
{ {
t_usize bucket_id; t_usize bucket_id;
t_usize all_id; t_usize all_id;

View file

@ -16,8 +16,7 @@
#include "me/types.h" #include "me/types.h"
#include <stdlib.h> #include <stdlib.h>
t_str *hmap_env_get(t_hashmap_env *hmap, t_str *hmap_env_get(t_hashmap_env *hmap, t_str *key)
t_str *key)
{ {
t_usize hashed_key; t_usize hashed_key;
t_entry_env *entry; t_entry_env *entry;

View file

@ -15,8 +15,7 @@
#include "me/vec/vec_ast.h" #include "me/vec/vec_ast.h"
#include <stdlib.h> #include <stdlib.h>
t_vec_ast vec_ast_new(t_usize capacity, t_vec_ast vec_ast_new(t_usize capacity, t_free_ast_item free_function)
t_free_ast_item free_function)
{ {
t_vec_ast out; t_vec_ast out;
@ -51,8 +50,8 @@ t_error vec_ast_reserve(t_vec_ast *vec, t_usize wanted_capacity)
new_capacity = (vec->capacity * 3) / 2 + 1; new_capacity = (vec->capacity * 3) / 2 + 1;
while (wanted_capacity > new_capacity) while (wanted_capacity > new_capacity)
new_capacity = (new_capacity * 3) / 2 + 1; new_capacity = (new_capacity * 3) / 2 + 1;
vec->buffer = vec->buffer = mem_realloc_array(vec->buffer, new_capacity,
mem_realloc_array(vec->buffer, new_capacity, sizeof(t_ast_node)); sizeof(t_ast_node));
vec->capacity = new_capacity; vec->capacity = new_capacity;
} }
return (NO_ERROR); return (NO_ERROR);

View file

@ -10,15 +10,13 @@
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "me/mem/mem.h"
#include "me/mem/mem.h"
#include "me/mem/mem.h" #include "me/mem/mem.h"
#include "me/types.h" #include "me/types.h"
#include "me/vec/vec_ast.h" #include "me/vec/vec_ast.h"
#include <stdlib.h> #include <stdlib.h>
t_error vec_ast_find(t_vec_ast *vec, t_error vec_ast_find(t_vec_ast *vec, bool (*fn)(const t_ast_node *),
bool (*fn)(const t_ast_node *), t_usize *index) t_usize *index)
{ {
t_usize idx; t_usize idx;
@ -37,8 +35,7 @@ t_error vec_ast_find(t_vec_ast *vec,
return (ERROR); return (ERROR);
} }
t_error vec_ast_find_starting(t_vec_ast *vec, t_error vec_ast_find_starting(t_vec_ast *vec, bool (*fn)(const t_ast_node *),
bool (*fn)(const t_ast_node *),
t_usize starting_index, t_usize *index) t_usize starting_index, t_usize *index)
{ {
t_usize idx; t_usize idx;
@ -58,8 +55,8 @@ t_error vec_ast_find_starting(t_vec_ast *vec,
return (ERROR); return (ERROR);
} }
t_error vec_ast_all(t_vec_ast *vec, t_error vec_ast_all(t_vec_ast *vec, bool (*fn)(const t_ast_node *),
bool (*fn)(const t_ast_node *), bool *result) bool *result)
{ {
t_usize idx; t_usize idx;
@ -76,8 +73,8 @@ t_error vec_ast_all(t_vec_ast *vec,
return (ERROR); return (ERROR);
} }
t_error vec_ast_any(t_vec_ast *vec, t_error vec_ast_any(t_vec_ast *vec, bool (*fn)(const t_ast_node *),
bool (*fn)(const t_ast_node *), bool *result) bool *result)
{ {
t_usize idx; t_usize idx;
@ -94,10 +91,8 @@ t_error vec_ast_any(t_vec_ast *vec,
return (ERROR); return (ERROR);
} }
void vec_ast_iter(t_vec_ast *vec, void vec_ast_iter(t_vec_ast *vec, void (*fn)(t_usize index,
void (*fn)(t_usize index, t_ast_node *value, t_ast_node *value, void *state), void *state)
void *state),
void *state)
{ {
t_usize idx; t_usize idx;

View file

@ -15,16 +15,15 @@
#include "me/vec/vec_ast.h" #include "me/vec/vec_ast.h"
#include <stdlib.h> #include <stdlib.h>
t_error vec_ast_push_front(t_vec_ast *vec, t_error vec_ast_push_front(t_vec_ast *vec, t_ast_node element)
t_ast_node element)
{ {
t_usize i; t_usize i;
if (vec->len == 0) if (vec->len == 0)
return (vec_ast_push(vec, element)); return (vec_ast_push(vec, element));
i = vec->len - 1; i = vec->len - 1;
if (vec->capacity < vec->len + 1 && if (vec->capacity < vec->len + 1 && vec_ast_reserve(vec, 3 * vec->len / 2
vec_ast_reserve(vec, 3 * vec->len / 2 + 1)) + 1))
return (ERROR); return (ERROR);
while (i > 0) while (i > 0)
{ {

View file

@ -1,7 +1,7 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* vec_ast.c :+: :+: :+: */ /* ast_functions4.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */ /* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
@ -39,16 +39,14 @@ void vec_ast_copy_into(t_vec_ast *vec, t_vec_ast *dest)
mem_copy(dest->buffer, vec->buffer, vec->len * sizeof(t_ast_node)); mem_copy(dest->buffer, vec->buffer, vec->len * sizeof(t_ast_node));
} }
struct s_vec_ast_splice_arguments vec_ast_splice_args( struct s_vec_ast_splice_arguments vec_ast_splice_args(t_usize index,
t_usize index, t_usize old_count, t_usize new_count, t_usize old_count, t_usize new_count, const t_ast_node *elements)
const t_ast_node *elements)
{ {
return ((struct s_vec_ast_splice_arguments){index, old_count, return ((struct s_vec_ast_splice_arguments){index, old_count, new_count,
new_count, elements}); elements});
} }
void vec_ast_splice(t_vec_ast *self, void vec_ast_splice(t_vec_ast *self, struct s_vec_ast_splice_arguments args)
struct s_vec_ast_splice_arguments args)
{ {
t_ast_node *contents; t_ast_node *contents;
t_u32 new_size; t_u32 new_size;
@ -61,9 +59,8 @@ void vec_ast_splice(t_vec_ast *self,
vec_ast_reserve(self, new_size); vec_ast_reserve(self, new_size);
contents = self->buffer; contents = self->buffer;
if (self->len > old_end) if (self->len > old_end)
mem_move(contents + new_end, mem_move(contents + new_end, contents + old_end, (self->len - old_end)
contents + old_end, * sizeof(t_ast_node));
(self->len - old_end) * sizeof(t_ast_node));
if (args.new_count > 0) if (args.new_count > 0)
{ {
if (args.elements) if (args.elements)

View file

@ -13,8 +13,7 @@
#include "me/types.h" #include "me/types.h"
#include "me/vec/vec_ast.h" #include "me/vec/vec_ast.h"
void vec_ast_sort(t_vec_ast *v, void vec_ast_sort(t_vec_ast *v, t_vec_ast_sort_fn is_sorted_fn)
t_vec_ast_sort_fn is_sorted_fn)
{ {
t_usize sorted_part; t_usize sorted_part;
t_usize i; t_usize i;

View file

@ -15,8 +15,7 @@
#include "me/vec/vec_estr.h" #include "me/vec/vec_estr.h"
#include <stdlib.h> #include <stdlib.h>
t_vec_estr vec_estr_new(t_usize capacity, t_vec_estr vec_estr_new(t_usize capacity, t_free_estr_item free_function)
t_free_estr_item free_function)
{ {
t_vec_estr out; t_vec_estr out;
@ -51,8 +50,8 @@ t_error vec_estr_reserve(t_vec_estr *vec, t_usize wanted_capacity)
new_capacity = (vec->capacity * 3) / 2 + 1; new_capacity = (vec->capacity * 3) / 2 + 1;
while (wanted_capacity > new_capacity) while (wanted_capacity > new_capacity)
new_capacity = (new_capacity * 3) / 2 + 1; new_capacity = (new_capacity * 3) / 2 + 1;
vec->buffer = vec->buffer = mem_realloc_array(vec->buffer, new_capacity,
mem_realloc_array(vec->buffer, new_capacity, sizeof(t_expandable_str)); sizeof(t_expandable_str));
vec->capacity = new_capacity; vec->capacity = new_capacity;
} }
return (NO_ERROR); return (NO_ERROR);

View file

@ -10,15 +10,13 @@
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "me/mem/mem.h"
#include "me/mem/mem.h"
#include "me/mem/mem.h" #include "me/mem/mem.h"
#include "me/types.h" #include "me/types.h"
#include "me/vec/vec_estr.h" #include "me/vec/vec_estr.h"
#include <stdlib.h> #include <stdlib.h>
t_error vec_estr_find(t_vec_estr *vec, t_error vec_estr_find(t_vec_estr *vec, bool (*fn)(const t_expandable_str *),
bool (*fn)(const t_expandable_str *), t_usize *index) t_usize *index)
{ {
t_usize idx; t_usize idx;
@ -38,8 +36,8 @@ t_error vec_estr_find(t_vec_estr *vec,
} }
t_error vec_estr_find_starting(t_vec_estr *vec, t_error vec_estr_find_starting(t_vec_estr *vec,
bool (*fn)(const t_expandable_str *), bool (*fn)(const t_expandable_str *), t_usize starting_index,
t_usize starting_index, t_usize *index) t_usize *index)
{ {
t_usize idx; t_usize idx;
@ -58,8 +56,8 @@ t_error vec_estr_find_starting(t_vec_estr *vec,
return (ERROR); return (ERROR);
} }
t_error vec_estr_all(t_vec_estr *vec, t_error vec_estr_all(t_vec_estr *vec, bool (*fn)(const t_expandable_str *),
bool (*fn)(const t_expandable_str *), bool *result) bool *result)
{ {
t_usize idx; t_usize idx;
@ -76,8 +74,8 @@ t_error vec_estr_all(t_vec_estr *vec,
return (ERROR); return (ERROR);
} }
t_error vec_estr_any(t_vec_estr *vec, t_error vec_estr_any(t_vec_estr *vec, bool (*fn)(const t_expandable_str *),
bool (*fn)(const t_expandable_str *), bool *result) bool *result)
{ {
t_usize idx; t_usize idx;
@ -94,10 +92,8 @@ t_error vec_estr_any(t_vec_estr *vec,
return (ERROR); return (ERROR);
} }
void vec_estr_iter(t_vec_estr *vec, void vec_estr_iter(t_vec_estr *vec, void (*fn)(t_usize index,
void (*fn)(t_usize index, t_expandable_str *value, t_expandable_str *value, void *state), void *state)
void *state),
void *state)
{ {
t_usize idx; t_usize idx;

View file

@ -15,16 +15,15 @@
#include "me/vec/vec_estr.h" #include "me/vec/vec_estr.h"
#include <stdlib.h> #include <stdlib.h>
t_error vec_estr_push_front(t_vec_estr *vec, t_error vec_estr_push_front(t_vec_estr *vec, t_expandable_str element)
t_expandable_str element)
{ {
t_usize i; t_usize i;
if (vec->len == 0) if (vec->len == 0)
return (vec_estr_push(vec, element)); return (vec_estr_push(vec, element));
i = vec->len - 1; i = vec->len - 1;
if (vec->capacity < vec->len + 1 && if (vec->capacity < vec->len + 1 && vec_estr_reserve(vec, 3 * vec->len / 2
vec_estr_reserve(vec, 3 * vec->len / 2 + 1)) + 1))
return (ERROR); return (ERROR);
while (i > 0) while (i > 0)
{ {

View file

@ -39,12 +39,11 @@ void vec_estr_copy_into(t_vec_estr *vec, t_vec_estr *dest)
mem_copy(dest->buffer, vec->buffer, vec->len * sizeof(t_expandable_str)); mem_copy(dest->buffer, vec->buffer, vec->len * sizeof(t_expandable_str));
} }
struct s_vec_estr_splice_arguments vec_estr_splice_args( struct s_vec_estr_splice_arguments vec_estr_splice_args(t_usize index,
t_usize index, t_usize old_count, t_usize new_count, t_usize old_count, t_usize new_count, const t_expandable_str *elements)
const t_expandable_str *elements)
{ {
return ((struct s_vec_estr_splice_arguments){index, old_count, return ((struct s_vec_estr_splice_arguments){index, old_count, new_count,
new_count, elements}); elements});
} }
void vec_estr_splice(t_vec_estr *self, void vec_estr_splice(t_vec_estr *self,
@ -61,9 +60,8 @@ void vec_estr_splice(t_vec_estr *self,
vec_estr_reserve(self, new_size); vec_estr_reserve(self, new_size);
contents = self->buffer; contents = self->buffer;
if (self->len > old_end) if (self->len > old_end)
mem_move(contents + new_end, mem_move(contents + new_end, contents + old_end, (self->len - old_end)
contents + old_end, * sizeof(t_expandable_str));
(self->len - old_end) * sizeof(t_expandable_str));
if (args.new_count > 0) if (args.new_count > 0)
{ {
if (args.elements) if (args.elements)

View file

@ -13,8 +13,7 @@
#include "me/types.h" #include "me/types.h"
#include "me/vec/vec_estr.h" #include "me/vec/vec_estr.h"
void vec_estr_sort(t_vec_estr *v, void vec_estr_sort(t_vec_estr *v, t_vec_estr_sort_fn is_sorted_fn)
t_vec_estr_sort_fn is_sorted_fn)
{ {
t_usize sorted_part; t_usize sorted_part;
t_usize i; t_usize i;

View file

@ -15,8 +15,7 @@
#include "me/vec/vec_pid.h" #include "me/vec/vec_pid.h"
#include <stdlib.h> #include <stdlib.h>
t_vec_pid vec_pid_new(t_usize capacity, t_vec_pid vec_pid_new(t_usize capacity, t_free_pid_item free_function)
t_free_pid_item free_function)
{ {
t_vec_pid out; t_vec_pid out;
@ -51,8 +50,8 @@ t_error vec_pid_reserve(t_vec_pid *vec, t_usize wanted_capacity)
new_capacity = (vec->capacity * 3) / 2 + 1; new_capacity = (vec->capacity * 3) / 2 + 1;
while (wanted_capacity > new_capacity) while (wanted_capacity > new_capacity)
new_capacity = (new_capacity * 3) / 2 + 1; new_capacity = (new_capacity * 3) / 2 + 1;
vec->buffer = vec->buffer = mem_realloc_array(vec->buffer, new_capacity,
mem_realloc_array(vec->buffer, new_capacity, sizeof(t_pid)); sizeof(t_pid));
vec->capacity = new_capacity; vec->capacity = new_capacity;
} }
return (NO_ERROR); return (NO_ERROR);

View file

@ -10,15 +10,12 @@
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "me/mem/mem.h"
#include "me/mem/mem.h"
#include "me/mem/mem.h" #include "me/mem/mem.h"
#include "me/types.h" #include "me/types.h"
#include "me/vec/vec_pid.h" #include "me/vec/vec_pid.h"
#include <stdlib.h> #include <stdlib.h>
t_error vec_pid_find(t_vec_pid *vec, t_error vec_pid_find(t_vec_pid *vec, bool (*fn)(const t_pid *), t_usize *index)
bool (*fn)(const t_pid *), t_usize *index)
{ {
t_usize idx; t_usize idx;
@ -37,8 +34,7 @@ t_error vec_pid_find(t_vec_pid *vec,
return (ERROR); return (ERROR);
} }
t_error vec_pid_find_starting(t_vec_pid *vec, t_error vec_pid_find_starting(t_vec_pid *vec, bool (*fn)(const t_pid *),
bool (*fn)(const t_pid *),
t_usize starting_index, t_usize *index) t_usize starting_index, t_usize *index)
{ {
t_usize idx; t_usize idx;
@ -58,8 +54,7 @@ t_error vec_pid_find_starting(t_vec_pid *vec,
return (ERROR); return (ERROR);
} }
t_error vec_pid_all(t_vec_pid *vec, t_error vec_pid_all(t_vec_pid *vec, bool (*fn)(const t_pid *), bool *result)
bool (*fn)(const t_pid *), bool *result)
{ {
t_usize idx; t_usize idx;
@ -76,8 +71,7 @@ t_error vec_pid_all(t_vec_pid *vec,
return (ERROR); return (ERROR);
} }
t_error vec_pid_any(t_vec_pid *vec, t_error vec_pid_any(t_vec_pid *vec, bool (*fn)(const t_pid *), bool *result)
bool (*fn)(const t_pid *), bool *result)
{ {
t_usize idx; t_usize idx;
@ -94,10 +88,8 @@ t_error vec_pid_any(t_vec_pid *vec,
return (ERROR); return (ERROR);
} }
void vec_pid_iter(t_vec_pid *vec, void vec_pid_iter(t_vec_pid *vec, void (*fn)(t_usize index, t_pid *value,
void (*fn)(t_usize index, t_pid *value, void *state), void *state)
void *state),
void *state)
{ {
t_usize idx; t_usize idx;

View file

@ -15,16 +15,15 @@
#include "me/vec/vec_pid.h" #include "me/vec/vec_pid.h"
#include <stdlib.h> #include <stdlib.h>
t_error vec_pid_push_front(t_vec_pid *vec, t_error vec_pid_push_front(t_vec_pid *vec, t_pid element)
t_pid element)
{ {
t_usize i; t_usize i;
if (vec->len == 0) if (vec->len == 0)
return (vec_pid_push(vec, element)); return (vec_pid_push(vec, element));
i = vec->len - 1; i = vec->len - 1;
if (vec->capacity < vec->len + 1 && if (vec->capacity < vec->len + 1 && vec_pid_reserve(vec, 3 * vec->len / 2
vec_pid_reserve(vec, 3 * vec->len / 2 + 1)) + 1))
return (ERROR); return (ERROR);
while (i > 0) while (i > 0)
{ {

View file

@ -39,16 +39,14 @@ void vec_pid_copy_into(t_vec_pid *vec, t_vec_pid *dest)
mem_copy(dest->buffer, vec->buffer, vec->len * sizeof(t_pid)); mem_copy(dest->buffer, vec->buffer, vec->len * sizeof(t_pid));
} }
struct s_vec_pid_splice_arguments vec_pid_splice_args( struct s_vec_pid_splice_arguments vec_pid_splice_args(t_usize index,
t_usize index, t_usize old_count, t_usize new_count, t_usize old_count, t_usize new_count, const t_pid *elements)
const t_pid *elements)
{ {
return ((struct s_vec_pid_splice_arguments){index, old_count, return ((struct s_vec_pid_splice_arguments){index, old_count, new_count,
new_count, elements}); elements});
} }
void vec_pid_splice(t_vec_pid *self, void vec_pid_splice(t_vec_pid *self, struct s_vec_pid_splice_arguments args)
struct s_vec_pid_splice_arguments args)
{ {
t_pid *contents; t_pid *contents;
t_u32 new_size; t_u32 new_size;
@ -61,17 +59,16 @@ void vec_pid_splice(t_vec_pid *self,
vec_pid_reserve(self, new_size); vec_pid_reserve(self, new_size);
contents = self->buffer; contents = self->buffer;
if (self->len > old_end) if (self->len > old_end)
mem_move(contents + new_end, mem_move(contents + new_end, contents + old_end, (self->len - old_end)
contents + old_end, * sizeof(t_pid));
(self->len - old_end) * sizeof(t_pid));
if (args.new_count > 0) if (args.new_count > 0)
{ {
if (args.elements) if (args.elements)
mem_copy((contents + args.index * sizeof(t_pid)), mem_copy((contents + args.index * sizeof(t_pid)), args.elements,
args.elements, args.new_count * sizeof(t_pid));
else
mem_set_zero((contents + args.index * sizeof(t_pid)),
args.new_count * sizeof(t_pid)); args.new_count * sizeof(t_pid));
else
mem_set_zero((contents + args.index * sizeof(t_pid)), args.new_count
* sizeof(t_pid));
} }
self->len += args.new_count - args.old_count; self->len += args.new_count - args.old_count;
} }

View file

@ -13,8 +13,7 @@
#include "me/types.h" #include "me/types.h"
#include "me/vec/vec_pid.h" #include "me/vec/vec_pid.h"
void vec_pid_sort(t_vec_pid *v, void vec_pid_sort(t_vec_pid *v, t_vec_pid_sort_fn is_sorted_fn)
t_vec_pid_sort_fn is_sorted_fn)
{ {
t_usize sorted_part; t_usize sorted_part;
t_usize i; t_usize i;

View file

@ -15,8 +15,7 @@
#include "me/vec/vec_str.h" #include "me/vec/vec_str.h"
#include <stdlib.h> #include <stdlib.h>
t_vec_str vec_str_new(t_usize capacity, t_vec_str vec_str_new(t_usize capacity, t_free_str_item free_function)
t_free_str_item free_function)
{ {
t_vec_str out; t_vec_str out;
@ -51,8 +50,8 @@ t_error vec_str_reserve(t_vec_str *vec, t_usize wanted_capacity)
new_capacity = (vec->capacity * 3) / 2 + 1; new_capacity = (vec->capacity * 3) / 2 + 1;
while (wanted_capacity > new_capacity) while (wanted_capacity > new_capacity)
new_capacity = (new_capacity * 3) / 2 + 1; new_capacity = (new_capacity * 3) / 2 + 1;
vec->buffer = vec->buffer = mem_realloc_array(vec->buffer, new_capacity,
mem_realloc_array(vec->buffer, new_capacity, sizeof(t_str)); sizeof(t_str));
vec->capacity = new_capacity; vec->capacity = new_capacity;
} }
return (NO_ERROR); return (NO_ERROR);

View file

@ -10,15 +10,12 @@
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "me/mem/mem.h"
#include "me/mem/mem.h"
#include "me/mem/mem.h" #include "me/mem/mem.h"
#include "me/types.h" #include "me/types.h"
#include "me/vec/vec_str.h" #include "me/vec/vec_str.h"
#include <stdlib.h> #include <stdlib.h>
t_error vec_str_find(t_vec_str *vec, t_error vec_str_find(t_vec_str *vec, bool (*fn)(const t_str *), t_usize *index)
bool (*fn)(const t_str *), t_usize *index)
{ {
t_usize idx; t_usize idx;
@ -37,8 +34,7 @@ t_error vec_str_find(t_vec_str *vec,
return (ERROR); return (ERROR);
} }
t_error vec_str_find_starting(t_vec_str *vec, t_error vec_str_find_starting(t_vec_str *vec, bool (*fn)(const t_str *),
bool (*fn)(const t_str *),
t_usize starting_index, t_usize *index) t_usize starting_index, t_usize *index)
{ {
t_usize idx; t_usize idx;
@ -58,8 +54,7 @@ t_error vec_str_find_starting(t_vec_str *vec,
return (ERROR); return (ERROR);
} }
t_error vec_str_all(t_vec_str *vec, t_error vec_str_all(t_vec_str *vec, bool (*fn)(const t_str *), bool *result)
bool (*fn)(const t_str *), bool *result)
{ {
t_usize idx; t_usize idx;
@ -76,8 +71,7 @@ t_error vec_str_all(t_vec_str *vec,
return (ERROR); return (ERROR);
} }
t_error vec_str_any(t_vec_str *vec, t_error vec_str_any(t_vec_str *vec, bool (*fn)(const t_str *), bool *result)
bool (*fn)(const t_str *), bool *result)
{ {
t_usize idx; t_usize idx;
@ -94,10 +88,8 @@ t_error vec_str_any(t_vec_str *vec,
return (ERROR); return (ERROR);
} }
void vec_str_iter(t_vec_str *vec, void vec_str_iter(t_vec_str *vec, void (*fn)(t_usize index, t_str *value,
void (*fn)(t_usize index, t_str *value, void *state), void *state)
void *state),
void *state)
{ {
t_usize idx; t_usize idx;

View file

@ -15,16 +15,15 @@
#include "me/vec/vec_str.h" #include "me/vec/vec_str.h"
#include <stdlib.h> #include <stdlib.h>
t_error vec_str_push_front(t_vec_str *vec, t_error vec_str_push_front(t_vec_str *vec, t_str element)
t_str element)
{ {
t_usize i; t_usize i;
if (vec->len == 0) if (vec->len == 0)
return (vec_str_push(vec, element)); return (vec_str_push(vec, element));
i = vec->len - 1; i = vec->len - 1;
if (vec->capacity < vec->len + 1 && if (vec->capacity < vec->len + 1 && vec_str_reserve(vec, 3 * vec->len / 2
vec_str_reserve(vec, 3 * vec->len / 2 + 1)) + 1))
return (ERROR); return (ERROR);
while (i > 0) while (i > 0)
{ {

View file

@ -39,16 +39,14 @@ void vec_str_copy_into(t_vec_str *vec, t_vec_str *dest)
mem_copy(dest->buffer, vec->buffer, vec->len * sizeof(t_str)); mem_copy(dest->buffer, vec->buffer, vec->len * sizeof(t_str));
} }
struct s_vec_str_splice_arguments vec_str_splice_args( struct s_vec_str_splice_arguments vec_str_splice_args(t_usize index,
t_usize index, t_usize old_count, t_usize new_count, t_usize old_count, t_usize new_count, const t_str *elements)
const t_str *elements)
{ {
return ((struct s_vec_str_splice_arguments){index, old_count, return ((struct s_vec_str_splice_arguments){index, old_count, new_count,
new_count, elements}); elements});
} }
void vec_str_splice(t_vec_str *self, void vec_str_splice(t_vec_str *self, struct s_vec_str_splice_arguments args)
struct s_vec_str_splice_arguments args)
{ {
t_str *contents; t_str *contents;
t_u32 new_size; t_u32 new_size;
@ -61,17 +59,16 @@ void vec_str_splice(t_vec_str *self,
vec_str_reserve(self, new_size); vec_str_reserve(self, new_size);
contents = self->buffer; contents = self->buffer;
if (self->len > old_end) if (self->len > old_end)
mem_move(contents + new_end, mem_move(contents + new_end, contents + old_end, (self->len - old_end)
contents + old_end, * sizeof(t_str));
(self->len - old_end) * sizeof(t_str));
if (args.new_count > 0) if (args.new_count > 0)
{ {
if (args.elements) if (args.elements)
mem_copy((contents + args.index * sizeof(t_str)), mem_copy((contents + args.index * sizeof(t_str)), args.elements,
args.elements, args.new_count * sizeof(t_str));
else
mem_set_zero((contents + args.index * sizeof(t_str)),
args.new_count * sizeof(t_str)); args.new_count * sizeof(t_str));
else
mem_set_zero((contents + args.index * sizeof(t_str)), args.new_count
* sizeof(t_str));
} }
self->len += args.new_count - args.old_count; self->len += args.new_count - args.old_count;
} }

View file

@ -13,8 +13,7 @@
#include "me/types.h" #include "me/types.h"
#include "me/vec/vec_str.h" #include "me/vec/vec_str.h"
void vec_str_sort(t_vec_str *v, void vec_str_sort(t_vec_str *v, t_vec_str_sort_fn is_sorted_fn)
t_vec_str_sort_fn is_sorted_fn)
{ {
t_usize sorted_part; t_usize sorted_part;
t_usize i; t_usize i;

View file

@ -15,8 +15,7 @@
#include "me/vec/vec_token.h" #include "me/vec/vec_token.h"
#include <stdlib.h> #include <stdlib.h>
t_vec_token vec_token_new(t_usize capacity, t_vec_token vec_token_new(t_usize capacity, t_free_token_item free_function)
t_free_token_item free_function)
{ {
t_vec_token out; t_vec_token out;
@ -51,8 +50,8 @@ t_error vec_token_reserve(t_vec_token *vec, t_usize wanted_capacity)
new_capacity = (vec->capacity * 3) / 2 + 1; new_capacity = (vec->capacity * 3) / 2 + 1;
while (wanted_capacity > new_capacity) while (wanted_capacity > new_capacity)
new_capacity = (new_capacity * 3) / 2 + 1; new_capacity = (new_capacity * 3) / 2 + 1;
vec->buffer = vec->buffer = mem_realloc_array(vec->buffer, new_capacity,
mem_realloc_array(vec->buffer, new_capacity, sizeof(t_token)); sizeof(t_token));
vec->capacity = new_capacity; vec->capacity = new_capacity;
} }
return (NO_ERROR); return (NO_ERROR);

View file

@ -10,15 +10,13 @@
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "me/mem/mem.h"
#include "me/mem/mem.h"
#include "me/mem/mem.h" #include "me/mem/mem.h"
#include "me/types.h" #include "me/types.h"
#include "me/vec/vec_token.h" #include "me/vec/vec_token.h"
#include <stdlib.h> #include <stdlib.h>
t_error vec_token_find(t_vec_token *vec, t_error vec_token_find(t_vec_token *vec, bool (*fn)(const t_token *),
bool (*fn)(const t_token *), t_usize *index) t_usize *index)
{ {
t_usize idx; t_usize idx;
@ -37,8 +35,7 @@ t_error vec_token_find(t_vec_token *vec,
return (ERROR); return (ERROR);
} }
t_error vec_token_find_starting(t_vec_token *vec, t_error vec_token_find_starting(t_vec_token *vec, bool (*fn)(const t_token *),
bool (*fn)(const t_token *),
t_usize starting_index, t_usize *index) t_usize starting_index, t_usize *index)
{ {
t_usize idx; t_usize idx;
@ -58,8 +55,8 @@ t_error vec_token_find_starting(t_vec_token *vec,
return (ERROR); return (ERROR);
} }
t_error vec_token_all(t_vec_token *vec, t_error vec_token_all(t_vec_token *vec, bool (*fn)(const t_token *),
bool (*fn)(const t_token *), bool *result) bool *result)
{ {
t_usize idx; t_usize idx;
@ -76,8 +73,8 @@ t_error vec_token_all(t_vec_token *vec,
return (ERROR); return (ERROR);
} }
t_error vec_token_any(t_vec_token *vec, t_error vec_token_any(t_vec_token *vec, bool (*fn)(const t_token *),
bool (*fn)(const t_token *), bool *result) bool *result)
{ {
t_usize idx; t_usize idx;
@ -94,10 +91,8 @@ t_error vec_token_any(t_vec_token *vec,
return (ERROR); return (ERROR);
} }
void vec_token_iter(t_vec_token *vec, void vec_token_iter(t_vec_token *vec, void (*fn)(t_usize index,
void (*fn)(t_usize index, t_token *value, t_token *value, void *state), void *state)
void *state),
void *state)
{ {
t_usize idx; t_usize idx;

View file

@ -15,16 +15,15 @@
#include "me/vec/vec_token.h" #include "me/vec/vec_token.h"
#include <stdlib.h> #include <stdlib.h>
t_error vec_token_push_front(t_vec_token *vec, t_error vec_token_push_front(t_vec_token *vec, t_token element)
t_token element)
{ {
t_usize i; t_usize i;
if (vec->len == 0) if (vec->len == 0)
return (vec_token_push(vec, element)); return (vec_token_push(vec, element));
i = vec->len - 1; i = vec->len - 1;
if (vec->capacity < vec->len + 1 && if (vec->capacity < vec->len + 1 && vec_token_reserve(vec, 3 * vec->len / 2
vec_token_reserve(vec, 3 * vec->len / 2 + 1)) + 1))
return (ERROR); return (ERROR);
while (i > 0) while (i > 0)
{ {

View file

@ -13,8 +13,7 @@
#include "me/types.h" #include "me/types.h"
#include "me/vec/vec_token.h" #include "me/vec/vec_token.h"
void vec_token_sort(t_vec_token *v, void vec_token_sort(t_vec_token *v, t_vec_token_sort_fn is_sorted_fn)
t_vec_token_sort_fn is_sorted_fn)
{ {
t_usize sorted_part; t_usize sorted_part;
t_usize i; t_usize i;