Merge pull request #944 from simdjson/issue680

Document the complexity of array.at
This commit is contained in:
Daniel Lemire 2020-06-18 18:24:08 -04:00 committed by GitHub
commit 2f6091419f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 1 deletions

View File

@ -80,7 +80,17 @@ public:
inline simdjson_result<element> at(const std::string_view &json_pointer) const noexcept;
/**
* Get the value at the given index.
* Get the value at the given index. This function has linear-time complexity and
* is equivalent to the following:
*
* size_t i=0;
* for (auto element : *this) {
* if (i == index) { return element; }
* i++;
* }
* return INDEX_OUT_OF_BOUNDS;
*
* Avoid calling the at() function repeatedly.
*
* @return The value at the given index, or:
* - INDEX_OUT_OF_BOUNDS if the array index is larger than an array length