Skip to content

Commit ddf2623

Browse files
committed
Rename lower_bound_and_found to try_find
Since I added `try_set_key_type` in #285, I want to name all helper methods consistently.
1 parent 8fa2d46 commit ddf2623

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
@@ -215,17 +215,17 @@ bool SortedDictType::is_nargs_good(char const* caller, Py_ssize_t nargs, int at_
215215
}
216216

217217
/**
218-
* Find the lower bound of the given good key and report whether it was found.
219-
* (To determine whether a good key is present, check the second element of the
218+
* Try to find the given good key.
219+
*
220+
* To determine whether a good key is present, check the second element of the
220221
* result; there is no meaningful performance impact of doing this instead of
221-
* calling `find` directly because it internally does the same thing done
222-
* here.)
222+
* calling `find` directly because it internally does the same thing done here.
223223
*
224224
* @param key Good key.
225225
*
226226
* @return The lower bound of the given key and whether it was found.
227227
*/
228-
std::pair<FwdIterType, bool> SortedDictType::lower_bound_and_found(PyObject* key)
228+
std::pair<FwdIterType, bool> SortedDictType::try_find(PyObject* key)
229229
{
230230
auto it = this->map->lower_bound(key);
231231
return { it, it != this->map->end() && !this->map->key_comp()(key, it->first) };
@@ -415,7 +415,7 @@ int SortedDictType::contains(PyObject* key, PyObject* value)
415415
{
416416
return -1;
417417
}
418-
auto [it, found] = this->lower_bound_and_found(key);
418+
auto [it, found] = this->try_find(key);
419419
if (!found)
420420
{
421421
return 0;
@@ -450,7 +450,7 @@ PyObject* SortedDictType::getitem(PyObject* key)
450450
{
451451
return nullptr;
452452
}
453-
auto [it, found] = this->lower_bound_and_found(key);
453+
auto [it, found] = this->try_find(key);
454454
if (!found)
455455
{
456456
PyErr_SetObject(PyExc_KeyError, key);
@@ -477,7 +477,7 @@ int SortedDictType::setitem(PyObject* key, PyObject* value)
477477

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

482482
if (value == nullptr)
483483
{
@@ -574,7 +574,7 @@ PyObject* SortedDictType::get(PyObject* const* args, Py_ssize_t nargs)
574574
{
575575
return nullptr;
576576
}
577-
auto [it, found] = this->lower_bound_and_found(key);
577+
auto [it, found] = this->try_find(key);
578578
if (found)
579579
{
580580
return Py_NewRef(it->second.value); // 🆕
@@ -604,7 +604,7 @@ PyObject* SortedDictType::setdefault(PyObject* const* args, Py_ssize_t nargs)
604604
{
605605
return nullptr;
606606
}
607-
auto [it, found] = this->lower_bound_and_found(key);
607+
auto [it, found] = this->try_find(key);
608608
if (found)
609609
{
610610
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
@@ -68,7 +68,7 @@ private:
6868
bool is_deletion_allowed(void);
6969
static bool is_deletion_allowed(Py_ssize_t);
7070
static bool is_nargs_good(char const*, Py_ssize_t, int, int);
71-
std::pair<FwdIterType, bool> lower_bound_and_found(PyObject*);
71+
std::pair<FwdIterType, bool> try_find(PyObject*);
7272
bool update_from_mapping(PyObject*);
7373
bool update_from_sequence(PyObject*);
7474
bool update_from_object(PyObject*);

0 commit comments

Comments
 (0)