1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * |
5 | * |
6 | * Deliantra is free software: you can redistribute it and/or modify it under |
6 | * Deliantra is free software: you can redistribute it and/or modify it under |
7 | * the terms of the Affero GNU General Public License as published by the |
7 | * the terms of the Affero GNU General Public License as published by the |
8 | * Free Software Foundation, either version 3 of the License, or (at your |
8 | * Free Software Foundation, either version 3 of the License, or (at your |
9 | * option) any later version. |
9 | * option) any later version. |
10 | * |
10 | * |
11 | * This program is distributed in the hope that it will be useful, |
11 | * This program is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * GNU General Public License for more details. |
14 | * GNU General Public License for more details. |
15 | * |
15 | * |
16 | * You should have received a copy of the Affero GNU General Public License |
16 | * You should have received a copy of the Affero GNU General Public License |
17 | * and the GNU General Public License along with this program. If not, see |
17 | * and the GNU General Public License along with this program. If not, see |
18 | * <http://www.gnu.org/licenses/>. |
18 | * <http://www.gnu.org/licenses/>. |
19 | * |
19 | * |
20 | * The authors can be reached via e-mail to <support@deliantra.net> |
20 | * The authors can be reached via e-mail to <support@deliantra.net> |
21 | */ |
21 | */ |
22 | |
22 | |
23 | #ifndef UTIL_H__ |
23 | #ifndef UTIL_H__ |
24 | #define UTIL_H__ |
24 | #define UTIL_H__ |
… | |
… | |
654 | } |
654 | } |
655 | }; |
655 | }; |
656 | |
656 | |
657 | // This container blends advantages of linked lists |
657 | // This container blends advantages of linked lists |
658 | // (efficiency) with vectors (random access) by |
658 | // (efficiency) with vectors (random access) by |
659 | // by using an unordered vector and storing the vector |
659 | // using an unordered vector and storing the vector |
660 | // index inside the object. |
660 | // index inside the object. |
661 | // |
661 | // |
662 | // + memory-efficient on most 64 bit archs |
662 | // + memory-efficient on most 64 bit archs |
663 | // + O(1) insert/remove |
663 | // + O(1) insert/remove |
664 | // + free unique (but varying) id for inserted objects |
664 | // + free unique (but varying) id for inserted objects |
… | |
… | |
701 | insert (&obj); |
701 | insert (&obj); |
702 | } |
702 | } |
703 | |
703 | |
704 | void erase (T *obj) |
704 | void erase (T *obj) |
705 | { |
705 | { |
706 | unsigned int pos = obj->*indexmember; |
706 | object_vector_index pos = obj->*indexmember; |
707 | obj->*indexmember = 0; |
707 | obj->*indexmember = 0; |
708 | |
708 | |
709 | if (pos < this->size ()) |
709 | if (pos < this->size ()) |
710 | { |
710 | { |
711 | (*this)[pos - 1] = (*this)[this->size () - 1]; |
711 | (*this)[pos - 1] = (*this)[this->size () - 1]; |