2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2014 Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #ifndef incl_HPHP_UTIL_MAPWALKER_H_
18 #define incl_HPHP_UTIL_MAPWALKER_H_
23 * MapWalker is designed to iterate over an ordered map and an ordered list of
24 * keys in parallel. Once created with a reference to a map, hasNext(key) will
25 * return true iff the next item in the map matches the given key. If it
26 * returns true, next() will return a reference to that element and advance its
27 * internal iterator. hasNext() can be used to check if the internal iterator
28 * is at the end of the map.
30 template<typename Map
>
32 typedef typename
Map::key_type Key
;
33 typedef typename
Map::mapped_type Value
;
34 typedef typename
Map::const_iterator ConstIter
;
36 explicit MapWalker(const Map
& m
)
41 bool hasNext() const {
42 return m_iter
!= m_map
.end();
45 bool hasNext(const Key
& key
) const {
46 assert(m_iter
== m_map
.end() || key
<= m_iter
->first
);
47 return m_iter
!= m_map
.end() && m_iter
->first
== key
;
51 assert(m_iter
!= m_map
.end());
52 auto const& val
= m_iter
->second
;
62 template<typename Map
>
63 MapWalker
<Map
> makeMapWalker(const Map
& m
) {
64 return MapWalker
<Map
>(m
);