nndeploy C++ API  0.2.0
nndeploy C++ API
util.h
Go to the documentation of this file.
1 #ifndef _NNDEPLOY_DEVICE_UTIL_H_
2 #define _NNDEPLOY_DEVICE_UTIL_H_
3 
4 namespace nndeploy {
5 namespace device {
6 
7 template <typename T>
8 base::Status insertStream(int &index, std::map<int, T> &stream_map,
9  const T &stream) {
10  if (stream_map.find(index) == stream_map.end()) {
11  stream_map[index] = stream;
12  return base::kStatusCodeOk;
13  } else {
14  if (index == INT_MAX - 1) {
15  index = 0;
16  }
17  index++;
18  return insertStream(index, stream_map, stream);
19  }
20 }
21 template <typename T>
22 int updateStreamIndex(std::map<int, T> &stream_map) {
23  // 得到map中倒数第二个元素
24  auto iter = stream_map.end();
25  iter--;
26  iter--;
27  int stream_index = iter->first;
28  return stream_index;
29 }
30 
31 } // namespace device
32 } // namespace nndeploy
33 
34 #endif /* _NNDEPLOY_DEVICE_UTIL_H_ */
@ kStatusCodeOk
Definition: status.h:13
int updateStreamIndex(std::map< int, T > &stream_map)
Definition: util.h:22
base::Status insertStream(int &index, std::map< int, T > &stream_map, const T &stream)
Definition: util.h:8