Skip to content

Commit 335fa3e

Browse files
authored
Rename lower_bound_and_found to try_find (#286)
Since I added `try_set_key_type` in #285, I want to name all helper methods consistently.
1 parent 8dde2ed commit 335fa3e

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

src/pysorteddict/sorted_dict_type.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -262,17 +262,17 @@ bool SortedDictType::is_nargs_good(char const* caller, Py_ssize_t nargs, int at_
262262
}
263263

264264
/**
265-
* Find the lower bound of the given good key and report whether it was found.
266-
* (To determine whether a good key is present, check the second element of the
265+
* Try to find the given good key.
266+
*
267+
* To determine whether a good key is present, check the second element of the
267268
* result; there is no meaningful performance impact of doing this instead of
268-
* calling `find` directly because it internally does the same thing done
269-
* here.)
269+
* calling `find` directly because it internally does the same thing done here.
270270
*
271271
* @param key Good key.
272272
*
273273
* @return The lower bound of the given key and whether it was found.
274274
*/
275-
std::pair<FwdIterType, bool> SortedDictType::lower_bound_and_found(PyObject* key)
275+
std::pair<FwdIterType, bool> SortedDictType::try_find(PyObject* key)
276276
{
277277
auto it = this->map->lower_bound(key);
278278
return { it, it != this->map->end() && !this->map->key_comp()(key, it->first) };
@@ -462,7 +462,7 @@ int SortedDictType::contains(PyObject* key, PyObject* value)
462462
{
463463
return -1;
464464
}
465-
auto [it, found] = this->lower_bound_and_found(key);
465+
auto [it, found] = this->try_find(key);
466466
if (!found)
467467
{
468468
return 0;
@@ -497,7 +497,7 @@ PyObject* SortedDictType::getitem(PyObject* key)
497497
{
498498
return nullptr;
499499
}
500-
auto [it, found] = this->lower_bound_and_found(key);
500+
auto [it, found] = this->try_find(key);
501501
if (!found)
502502
{
503503
PyErr_SetObject(PyExc_KeyError, key);
@@ -524,7 +524,7 @@ int SortedDictType::setitem(PyObject* key, PyObject* value)
524524

525525
// Insertion will be faster if the approximate location is known. Hence,
526526
// look for the nearest match.
527-
auto [it, found] = this->lower_bound_and_found(key);
527+
auto [it, found] = this->try_find(key);
528528

529529
if (value == nullptr)
530530
{
@@ -621,7 +621,7 @@ PyObject* SortedDictType::get(PyObject* const* args, Py_ssize_t nargs)
621621
{
622622
return nullptr;
623623
}
624-
auto [it, found] = this->lower_bound_and_found(key);
624+
auto [it, found] = this->try_find(key);
625625
if (found)
626626
{
627627
return Py_NewRef(it->second.value); // 🆕
@@ -651,7 +651,7 @@ PyObject* SortedDictType::setdefault(PyObject* const* args, Py_ssize_t nargs)
651651
{
652652
return nullptr;
653653
}
654-
auto [it, found] = this->lower_bound_and_found(key);
654+
auto [it, found] = this->try_find(key);
655655
if (found)
656656
{
657657
return Py_NewRef(it->second.value); // 🆕

src/pysorteddict/sorted_dict_type.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ private:
6969
bool is_deletion_allowed(void);
7070
static bool is_deletion_allowed(Py_ssize_t);
7171
static bool is_nargs_good(char const*, Py_ssize_t, int, int);
72-
std::pair<FwdIterType, bool> lower_bound_and_found(PyObject*);
72+
std::pair<FwdIterType, bool> try_find(PyObject*);
7373
bool update_from_mapping(PyObject*);
7474
bool update_from_sequence(PyObject*);
7575
bool update_from_object(PyObject*);

0 commit comments

Comments
 (0)