|
6 | 6 |
|
7 | 7 | #include <argon/vm/runtime.h>
|
8 | 8 |
|
| 9 | +#include <argon/vm/datatype/support/common.h> |
| 10 | + |
9 | 11 | #include <argon/vm/datatype/boolean.h>
|
10 | 12 | #include <argon/vm/datatype/bounds.h>
|
11 | 13 | #include <argon/vm/datatype/option.h>
|
@@ -114,6 +116,42 @@ ARGON_METHOD(list_insert, insert,
|
114 | 116 | return ok ? (ArObject *) IncRef(self) : nullptr;
|
115 | 117 | }
|
116 | 118 |
|
| 119 | +ARGON_METHOD(list_max, max, |
| 120 | + "Returns the item with the highest value.\n" |
| 121 | + "\n" |
| 122 | + "- Returns: Highest value.\n" |
| 123 | + "\n" |
| 124 | + "# SEE\n" |
| 125 | + "- min\n", |
| 126 | + nullptr, false, false) { |
| 127 | + auto *self = (List *) _self; |
| 128 | + ArObject *max = nullptr; |
| 129 | + |
| 130 | + std::shared_lock _(self->rwlock); |
| 131 | + |
| 132 | + support::MaxMin(self->objects, &max, self->length, false); |
| 133 | + |
| 134 | + return max; |
| 135 | +} |
| 136 | + |
| 137 | +ARGON_METHOD(list_min, min, |
| 138 | + "Returns the item with the lowest value.\n" |
| 139 | + "\n" |
| 140 | + "- Returns: Lowest value.\n" |
| 141 | + "\n" |
| 142 | + "# SEE\n" |
| 143 | + "- max\n", |
| 144 | + nullptr, false, false) { |
| 145 | + auto *self = (List *) _self; |
| 146 | + ArObject *min = nullptr; |
| 147 | + |
| 148 | + std::shared_lock _(self->rwlock); |
| 149 | + |
| 150 | + support::MaxMin(self->objects, &min, self->length, true); |
| 151 | + |
| 152 | + return min; |
| 153 | +} |
| 154 | + |
117 | 155 | ARGON_METHOD(list_pop, pop,
|
118 | 156 | "Remove and returns the item at the end of the list.\n"
|
119 | 157 | "\n"
|
@@ -193,6 +231,8 @@ const FunctionDef list_methods[] = {
|
193 | 231 | list_extend,
|
194 | 232 | list_find,
|
195 | 233 | list_insert,
|
| 234 | + list_max, |
| 235 | + list_min, |
196 | 236 | list_pop,
|
197 | 237 | list_remove,
|
198 | 238 | list_reverse,
|
|
0 commit comments