diff --git a/Documentation.md b/Documentation.md index 72956ed..757de4e 100644 --- a/Documentation.md +++ b/Documentation.md @@ -2802,37 +2802,39 @@ Removes a matching element from the set using the comparator function, only if t ## [ \_max() ](#treeset_function_index) -Returns the greatest element present in a given set, according to the set comparator function. +Retrieves the greatest element present in a given set, according to the set comparator function. #### Declaration -> `FMOD V PFX##_max(SNAME *_set_);` +> `FMOD bool PFX##_max(SNAME *_set_, V *value);` #### Parameters 1. `SNAME *_set_` - Target TreeSet. +2. `V *value` - The resulting, greatest value in the set. #### Returns -1. `V` - The greatest element in the set. -2. `0` or `NULL` - If the set is empty. +1. `true` - If the set is not empty and a valid value was found. +2. `false` - If the set is empty and no valid value was found. ## [ \_min() ](#treeset_function_index) -Returns the smallest element present in a given set, according to the set comparator function. +Retrieves the smallest element present in a given set, according to the set comparator function. #### Declaration -> `FMOD V PFX##_in(SNAME *_set_);` +> `FMOD bool PFX##_min(SNAME *_set_, V *value);` #### Parameters 1. `SNAME *_set_` - Target TreeSet. +2. `V *value` - The resulting, smallest value in the set. #### Returns -1. `V` - The smallest element in the set. -2. `0` or `NULL` - If the set is empty. +1. `true` - If the set is not empty and a valid value was found. +2. `false` - If the set is empty and no valid value was found. ## [ \_contains() ](#treeset_function_index) diff --git a/src/treeset.h b/src/treeset.h index 84aea5d..a08cef3 100644 --- a/src/treeset.h +++ b/src/treeset.h @@ -108,8 +108,8 @@ FMOD bool PFX##_insert_if(SNAME *_set_, V element, bool condition); \ FMOD bool PFX##_remove_if(SNAME *_set_, V element, bool condition); \ /* Element Access */ \ - FMOD V PFX##_max(SNAME *_set_); \ - FMOD V PFX##_min(SNAME *_set_); \ + FMOD bool PFX##_max(SNAME *_set_, V *value); \ + FMOD bool PFX##_min(SNAME *_set_, V *value); \ /* Collection State */ \ FMOD bool PFX##_contains(SNAME *_set_, V element); \ FMOD bool PFX##_empty(SNAME *_set_); \ @@ -425,30 +425,34 @@ return false; \ } \ \ - FMOD V PFX##_max(SNAME *_set_) \ + FMOD bool PFX##_max(SNAME *_set_, V *value) \ { \ if (PFX##_empty(_set_)) \ - return 0; \ + return false; \ \ SNAME##_node *scan = _set_->root; \ \ while (scan->right != NULL) \ scan = scan->right; \ \ - return scan->value; \ + *value = scan->value; \ + \ + return true; \ } \ \ - FMOD V PFX##_min(SNAME *_set_) \ + FMOD bool PFX##_min(SNAME *_set_, V *value) \ { \ if (PFX##_empty(_set_)) \ - return 0; \ + return false; \ \ SNAME##_node *scan = _set_->root; \ \ while (scan->left != NULL) \ scan = scan->left; \ \ - return scan->value; \ + *value = scan->value; \ + \ + return true; \ } \ \ FMOD bool PFX##_contains(SNAME *_set_, V element) \