]>
git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gprofng/src/IndexMap2D.h
1 /* Copyright (C) 2021 Free Software Foundation, Inc.
4 This file is part of GNU Binutils.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
22 * Index Map2D implementation.
24 * Index Map2D is dynamic two dimensional array
27 #ifndef _DBE_INDEXMAP2D_H
28 #define _DBE_INDEXMAP2D_H
34 template <typename Key1_t
, typename Key2_t
, typename Value_t
>
35 class IndexMap2D
: public Map2D
<Key1_t
, Key2_t
, Value_t
>
42 void put (Key1_t key1
, Key2_t key2
, Value_t val
);
43 Value_t
get (Key1_t key1
, Key2_t key2
);
44 Value_t
get (Key1_t key1
, Key2_t key2
,
45 typename Map2D
<Key1_t
, Key2_t
, Value_t
>::Relation rel
);
46 Value_t
remove (Key1_t key1
, Key2_t key2
);
50 Vector
<Vector
<Value_t
>*> *map1
;
53 template <typename Key1_t
, typename Key2_t
, typename Value_t
>
54 IndexMap2D
<Key1_t
, Key2_t
, Value_t
>::IndexMap2D ()
56 map1
= new Vector
<Vector
<Value_t
>*>;
59 template <typename Key1_t
, typename Key2_t
, typename Value_t
>
60 IndexMap2D
<Key1_t
, Key2_t
, Value_t
>::~IndexMap2D ()
66 template <typename Key1_t
, typename Key2_t
, typename Value_t
>
68 IndexMap2D
<Key1_t
, Key2_t
, Value_t
>::put (Key1_t key1
, Key2_t key2
, Value_t val
)
70 if (key1
< 0 || key2
< 0)
72 Vector
<Value_t
> *map2
= NULL
;
73 if (key1
< map1
->size ())
74 map2
= map1
->fetch ((int) key1
);
77 map2
= new Vector
<Value_t
>;
78 map1
->store ((int) key1
, map2
);
80 map2
->store ((int) key2
, val
);
83 template <typename Key1_t
, typename Key2_t
, typename Value_t
>
85 IndexMap2D
<Key1_t
, Key2_t
, Value_t
>::get (Key1_t key1
, Key2_t key2
)
87 if (key1
< 0 || key1
>= map1
->size () || key2
< 0)
89 Vector
<Value_t
> *map2
= map1
->fetch ((int) key1
);
90 if (map2
== NULL
|| key2
>= map2
->size ())
92 return map2
->fetch ((int) key2
);
95 template <typename Key1_t
, typename Key2_t
, typename Value_t
>
97 IndexMap2D
<Key1_t
, Key2_t
, Value_t
>::get (Key1_t key1
, Key2_t key2
,
98 typename Map2D
<Key1_t
, Key2_t
, Value_t
>::Relation rel
)
100 if (rel
!= Map2D
<Key1_t
, Key2_t
, Value_t
>::REL_EQEQ
)
102 return get (key1
, key2
);
105 template <typename Key1_t
, typename Key2_t
, typename Value_t
>
107 IndexMap2D
<Key1_t
, Key2_t
, Value_t
>::remove (Key1_t key1
, Key2_t key2
)
109 if (key1
< 0 || key1
>= map1
->size () || key2
< 0)
111 Vector
<Value_t
> *map2
= map1
->fetch ((int) key1
);
112 if (map2
== NULL
|| key2
>= map2
->size ())
114 Value_t res
= map2
->fetch ((int) key2
);
115 map2
->store ((int) key2
, (Value_t
) 0);