00001 /* Part of the culibs project, <http://www.eideticdew.org/culibs/>. 00002 * Copyright (C) 2003--2007 Petter Urkedal <urkedal@nbi.dk> 00003 * 00004 * This program is free software: you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation, either version 3 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 */ 00017 00018 #ifndef CUCON_LOGCHAIN_H 00019 #define CUCON_LOGCHAIN_H 00020 00021 #include <cucon/fwd.h> 00022 #include <assert.h> 00023 00024 #ifdef CU_NDEBUG 00025 # define CUCON_LOGCHAIN_NDEBUG 1 00026 #endif 00027 00028 CU_BEGIN_DECLARATIONS 00029 /*!\defgroup cucon_logchain cucon/logchain.h: Chained chunks of memory with logarithmic time access 00030 * @{\ingroup cucon_deprecated_mod 00031 * \deprecated Use \ref cucon_frame_h */ 00032 00033 #define cuconP_LOGCHAIN_LINK(logchain, i) (((void **)(logchain))[-i-1]) 00034 00035 /* An unsigned integer type which can hold the depth of a logchain. */ 00036 typedef unsigned int cucon_logchain_depth_t; 00037 00038 /* Create a logchain of size 'size' as a root logchain if 'logchain_prev' is 00039 * NULL, else as a continuation of 'logchain_prev'. */ 00040 void *cucon_logchain_galloc(cucon_logchain_depth_t depth, size_t size, 00041 void *lch_prev); 00042 00043 void *cuconP_logchain_find_nontrivial(void *, size_t, size_t); 00044 00045 /* Return the logchain at 'dst_depth' given that of 'src_lch' at depth 00046 * 'src_depth'. Pre: 'src_depth ≤ dst_depth' */ 00047 CU_SINLINE void * 00048 cucon_logchain_find(void *src_lch, cucon_logchain_depth_t src_depth, 00049 cucon_logchain_depth_t dst_depth) 00050 { 00051 if (src_depth == dst_depth) 00052 return src_lch; 00053 else 00054 return cuconP_logchain_find_nontrivial(src_lch, src_depth, dst_depth); 00055 } 00056 00057 /* Equivalent to 'cucon_logchain_find(logchain, src_depth, src_depth - 1)'. */ 00058 CU_SINLINE void * 00059 cucon_logchain_prev(void *logchain, cucon_logchain_depth_t src_depth) 00060 { 00061 assert(src_depth > 0); 00062 return cuconP_LOGCHAIN_LINK(logchain, 0); 00063 } 00064 00065 /*!@}*/ 00066 CU_END_DECLARATIONS 00067 00068 #endif