00001 /* 00002 * PROPRIETARY INFORMATION. This software is proprietary to 00003 * Side Effects Software Inc., and is not to be reproduced, 00004 * transmitted, or disclosed in any way without written permission. 00005 * 00006 * Produced by: 00007 * Jeff Lait 00008 * Side Effects Software Inc 00009 * 477 Richmond Street West 00010 * Toronto, Ontario 00011 * Canada M5V 3E7 00012 * 416-504-9876 00013 * 00014 * NAME: UT_ArrayHelp.h ( UT Library, C++) 00015 * 00016 * COMMENTS: 00017 * Provides simple helper functions for the UT_*Array and UT_Symbol/ 00018 * HashTable classes. 00019 * 00020 * Should be private to the UT library, but needs to be exported 00021 * so NT style template instantiation will work. 00022 */ 00023 00024 #ifndef __UT_ArrayHelp__ 00025 #define __UT_ArrayHelp__ 00026 00027 #include "UT_API.h" 00028 typedef int (*ut_ptr_compare_func_t)(const void *, const void *); 00029 00030 #define SMALL_ALLOC 4 00031 #define BIG_ALLOC 128 00032 00033 // This routine describes how to change the size of an array. 00034 // It must increase the current_size by at least one! 00035 static inline unsigned int 00036 bumpAlloc(unsigned int current_size) 00037 { 00038 unsigned bump; 00039 00040 // For small values, we increment in by fixed amounts. For 00041 // large values, we increment by one eighth of the current size. 00042 // This prevents n^2 behaviour with allocation one element at a time. 00043 // A factor of 1/8 will waste 1/16 the memory on average, and will 00044 // double the size of the array in approximately 6 reallocations. 00045 if (current_size < BIG_ALLOC) 00046 bump = SMALL_ALLOC; 00047 else if (current_size < BIG_ALLOC * 8) 00048 bump = BIG_ALLOC; 00049 else 00050 bump = current_size >> 3; // Divided by 8. 00051 00052 current_size += bump; 00053 return current_size; 00054 } 00055 00056 // This function is used by the symbol tables to bump to the next/previous 00057 // prime size. 00058 UT_API int UTbumpAllocToPrime(int current_size); 00059 UT_API int UTdecreaseAllocToPrime(int current_size); 00060 00061 #endif 00062
1.5.9