Changed TreeSet max and min to be compatible with the TreeMap and the hash collections
This commit is contained in:
1 parent
a9c7439d15
commit
efdb1c80a3
2 files changed
+22
-16
No files matched your search
+10
-8
@@ -2802,37 +2802,39 @@ Removes a matching element from the set using the comparator function, only if t
|
||||
|
||||
## [<span id="treeset_max"> \_max() </span>](#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.
|
||||
|
||||
## [<span id="treeset_min"> \_min() </span>](#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.
|
||||
|
||||
## [<span id="treeset_contains"> \_contains() </span>](#treeset_function_index)
|
||||
|
||||
|
||||
+12
-8
@@ -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) \
|
||||
|
||||
Reference in new issue
Block a user