deploy: a47170346a
This commit is contained in:
1 parent
b36f8a9821
commit
11a863958e
1180 files changed
+14211
-6025
No files matched your search
@@ -22,11 +22,11 @@ No-throw guarantee: this function never throws exceptions.
|
||||
|
||||
## Complexity
|
||||
|
||||
Linear in the number of members: unlike the lookup functions, `count()` does not stop at the first match, because it has to count every member with the key. Members are compared one after another, in document order. Each comparison first checks the key's length -- already known from the index, without reading the key bytes -- before comparing its content. The hash index of the keys of objects with 128 or more members does not help here, since every member is visited.
|
||||
Linear in the number of members: unlike the lookup functions, `count()` does not stop at the first match, because it has to count every member with the key. Members are compared one after another, in document order. Each comparison first checks the key's length — already known from the index, without reading the key bytes — before comparing its content. The hash index of the keys of objects with 128 or more members does not help here, since every member is visited.
|
||||
|
||||
## Notes
|
||||
|
||||
This method always returns `0` when the value is not an object -- including a [discarded](https://json.nlohmann.me/api/basic_json_view/is_discarded/index.md) view.
|
||||
This method always returns `0` when the value is not an object — including a [discarded](https://json.nlohmann.me/api/basic_json_view/is_discarded/index.md) view.
|
||||
|
||||
If the source text repeats a key, `count()` returns more than `1` for it, even though the [materialized](https://json.nlohmann.me/api/basic_json_view/materialize/index.md) value (like the result of `parse()`) would have only one member with that key. Hence `count(key) > 1` detects duplicate keys. This is unlike the lookup functions ([`operator[]`](https://json.nlohmann.me/api/basic_json_view/operator%5B%5D/index.md), [`at`](https://json.nlohmann.me/api/basic_json_view/at/index.md), [`find`](https://json.nlohmann.me/api/basic_json_view/find/index.md), [`contains`](https://json.nlohmann.me/api/basic_json_view/contains/index.md)), which resolve to the *first* member; see the [Notes on duplicate keys](https://json.nlohmann.me/api/basic_json_view/operator%5B%5D/#notes) of `operator[]`.
|
||||
|
||||
@@ -80,8 +80,8 @@ transaction 2 has 2 "amount" fields
|
||||
|
||||
## See also
|
||||
|
||||
- [find](https://json.nlohmann.me/api/basic_json_view/find/index.md) - find a value in an object
|
||||
- [contains](https://json.nlohmann.me/api/basic_json_view/contains/index.md) - checks whether a key exists
|
||||
- [`find`](https://json.nlohmann.me/api/basic_json_view/find/index.md) - find a value in an object
|
||||
- [`contains`](https://json.nlohmann.me/api/basic_json_view/contains/index.md) - checks whether a key exists
|
||||
- [`BasicJsonType::count`](https://json.nlohmann.me/api/basic_json/count/index.md) - the corresponding function of `basic_json`
|
||||
|
||||
## Version history
|
||||
|
||||
Reference in new issue
Block a user