> On Nov. 19, 2014, 9:09 p.m., Ben Mahler wrote:
> > 3rdparty/libprocess/3rdparty/stout/include/stout/hashmap.hpp, line 91
> > <https://reviews.apache.org/r/28256/diff/1/?file=770267#file770267line91>
> >
> > Doesn't look like you need this? Can't you just compoase .contains()
> > and .put() in the caller?
I attached this to the wrong patchset, not needed for review request 28257 /
adding prefix paths. It was used by my proxy endpoint which sits on top of the
two patchsets I just posted.
For this instance yes I can do contains/put in the caller if that is preferred.
For unique-keyed containers "insert if not exists" and "insert or update if
exists" are fairly common patterns which I think helper functions make easier.
Both have been voted into the C++17 standard currently (insert_or_assign,
try_emplace). So I'd rather just have the pattern in one normalized place,
especially since people tend to get the implementations a little bit off.
try_emplace can actually be more efficient with move semantics than not having
it.
put() in the current codebase isn't actually coded efficiently from an STL
perspective, we nedlessly scan a chunk of the container multiple times to find
the right insertion point. The code should be roughly:
```
it = find(name)
if(it == end) {
// There is no hint, so insert is the best we can do.
insert(make_pair(name, value));
} else {
// We kno right where the node should go, so insert there.
it = erase(it);
emplace_hint(it, make_pair(name, value))
}
```
- Cody
-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/28256/#review62231
-----------------------------------------------------------
On Nov. 19, 2014, 9:01 p.m., Cody Maloney wrote:
>
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviews.apache.org/r/28256/
> -----------------------------------------------------------
>
> (Updated Nov. 19, 2014, 9:01 p.m.)
>
>
> Review request for mesos.
>
>
> Repository: mesos-git
>
>
> Description
> -------
>
> Add tryInsert to hashmap
>
>
> Diffs
> -----
>
> 3rdparty/libprocess/3rdparty/stout/include/stout/hashmap.hpp
> aa4d9ba68a27c1a7dea8cfe948a90487c4708add
> 3rdparty/libprocess/3rdparty/stout/tests/hashmap_tests.cpp
> eb3abfc9ba62f92d2ed5bc0e1c093791003a8319
>
> Diff: https://reviews.apache.org/r/28256/diff/
>
>
> Testing
> -------
>
> make distcheck ubuntu 14.04
>
>
> Thanks,
>
> Cody Maloney
>
>