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. |
… | |
… | |
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]; |