// This file is part of The New Aspell // Copyright (C) 2001 by Kevin Atkinson under the GNU LGPL license // version 2.0 or 2.1. You should have received a copy of the LGPL // license along with this library if you did not you can find // it at http://www.gnu.org/. #ifndef autil__block_slist_t_hh #define autil__block_slist_t_hh #include #include #include "block_slist.hpp" namespace acommon { template void BlockSList::add_block(unsigned int num) { assert (reinterpret_cast(&(first_available->next)) == reinterpret_cast(first_available)); const unsigned int ptr_offset = reinterpret_cast(&(first_available->data)) - reinterpret_cast(&(first_available->next)); void * block = malloc( ptr_offset + sizeof(Node) * num ); *reinterpret_cast(block) = first_block; first_block = block; Node * first = reinterpret_cast(reinterpret_cast(block) + ptr_offset); Node * i = first; Node * last = i + num; while (i + 1 != last) { i->next = i + 1; i = i + 1; } i->next = 0; first_available = first; } template void BlockSList::clear() { void * i = first_block; while (i != 0) { void * n = *reinterpret_cast(i); free(i); i = n; } first_block = 0; first_available = 0; } } #endif