├── CMakeLists.txt ├── Makefile.lcc ├── Makefile.lcc64 ├── Makefile.msvc ├── Makefile.old ├── README ├── bitstrings.c ├── bloom.c ├── buffer.c ├── ccl_internal.h ├── ccldoc ├── AbstractIterator.png ├── AuxiliaryInterfaces.png ├── Basic.png ├── BloomFilter.png ├── Circular.png ├── Containers.png ├── DListVocabulary.png ├── Dictionary.png ├── Feux.png ├── HashTable.png ├── Introduction.tex ├── Iterator.png ├── ListContainerSourceFiles.png ├── ListContainerSpecializations.png ├── ListVocabulary.png ├── Makefile ├── Memorymanagement.png ├── NamingConventions.png ├── Pool.png ├── Returncodes.png ├── SingleLinkedList.png ├── StreamBuffer.png ├── ValArray.png ├── Vector.tex ├── VectorVocabulary.png ├── Vocabulary.png ├── bitstrings.png ├── ccl.tex ├── dotable.c ├── intro.tex ├── lcc-dirs.png ├── list.png ├── rgb.tex └── tth.c ├── containers.h ├── debian ├── changelog ├── compat ├── control ├── libccl-dev.dirs ├── libccl-dev.install ├── libccl1.dirs ├── libccl1.install └── rules ├── deque.c ├── dictionary.c ├── dictionarygen.c ├── dlist.c ├── dlistgen.c ├── dlistgen.h ├── doubledlist.c ├── doubledlist.h ├── doublelist.c ├── doublelist.h ├── error.c ├── fgetline.c ├── generic.c ├── hashtable.c ├── heap.c ├── iMask.c ├── intdlist.c ├── intdlist.h ├── intlist.c ├── intlist.h ├── list.c ├── listgen.c ├── listgen.h ├── longlongdlist.c ├── longlongdlist.h ├── longlonglist.c ├── longlonglist.h ├── malloc_debug.c ├── memorymanager.c ├── observer.c ├── pool.c ├── pooldebug.c ├── priorityqueue.c ├── qsort_r.c ├── qsortex.c ├── queue.c ├── redblacktree.c ├── scapegoat.c ├── searchtree.c ├── sequential.c ├── smallpool.c ├── stdint.h.noc99 ├── strcollection.c ├── strcollectiongen.c ├── stringlist.c ├── stringlist.h ├── stringlistgen.c ├── stringlistgen.h ├── test.c ├── valarray.h ├── valarraydouble.c ├── valarrayfloat.c ├── valarraygen.c ├── valarraygen.h ├── valarrayint.c ├── valarraylongdouble.c ├── valarraylonglong.c ├── valarrayshort.c ├── valarraysize_t.c ├── valarrayuint.c ├── valarrayulonglong.c ├── vector.c ├── vectorgen.c ├── vectorgen.h ├── vectorsize_t.c ├── wdictionary.c ├── wstrcollection.c ├── wstringlist.c └── wstringlist.h /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.6) 2 | project(ccl C) 3 | 4 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake") 5 | 6 | if(NOT CMAKE_BUILD_TYPE) 7 | message(STATUS "No build type selected, defaulting to RelWithDebInfo") 8 | set(CMAKE_BUILD_TYPE "RelWithDebInfo") 9 | endif(NOT CMAKE_BUILD_TYPE) 10 | 11 | execute_process(COMMAND sh -c "head -1 debian/changelog | grep -o -E '\\([^)]+' | cut -b2-" 12 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 13 | OUTPUT_VARIABLE DEB_VERSION 14 | OUTPUT_STRIP_TRAILING_WHITESPACE 15 | ) 16 | 17 | string(REGEX MATCHALL "[^.]+" DEB_VERSION_LIST "${DEB_VERSION}") 18 | list(GET DEB_VERSION_LIST 0 VERSION_MAJOR) 19 | list(GET DEB_VERSION_LIST 1 VERSION_MINOR) 20 | list(GET DEB_VERSION_LIST 2 VERSION_PATCH) 21 | set(VERSION_STRING ${DEB_VERSION}) 22 | 23 | set(CMAKE_C_FLAGS "-Wall -Wno-pointer-sign -Werror") 24 | add_definitions(-DUNIX) 25 | 26 | set(CCL_SOURCES 27 | "vector.c" 28 | "error.c" 29 | "dlist.c" 30 | "qsortex.c" 31 | "bitstrings.c" 32 | "generic.c" 33 | "dictionary.c" 34 | "wdictionary.c" 35 | "list.c" 36 | "strcollection.c" 37 | "searchtree.c" 38 | "heap.c" 39 | "malloc_debug.c" 40 | "bloom.c" 41 | "fgetline.c" 42 | "pool.c" 43 | "pooldebug.c" 44 | "redblacktree.c" 45 | "scapegoat.c" 46 | "queue.c" 47 | "buffer.c" 48 | "observer.c" 49 | "valarraydouble.c" 50 | "valarrayint.c" 51 | "vectorsize_t.c" 52 | "valarraylongdouble.c" 53 | "valarrayshort.c" 54 | "valarrayfloat.c" 55 | "valarrayuint.c" 56 | "valarraylonglong.c" 57 | "valarrayulonglong.c" 58 | "memorymanager.c" 59 | "sequential.c" 60 | "iMask.c" 61 | "deque.c" 62 | "hashtable.c" 63 | "wstrcollection.c" 64 | "stringlist.c" 65 | "wstringlist.c" 66 | "priorityqueue.c" 67 | "intlist.c" 68 | "doublelist.c" 69 | "longlonglist.c" 70 | "intdlist.c" 71 | "doubledlist.c" 72 | "longlongdlist.c" 73 | ) 74 | 75 | set(CCL_HEADERS 76 | "containers.h" 77 | "dlistgen.h" 78 | "doubledlist.h" 79 | "doublelist.h" 80 | "intdlist.h" 81 | "intlist.h" 82 | "listgen.h" 83 | "longlongdlist.h" 84 | "longlonglist.h" 85 | "stringlistgen.h" 86 | "stringlist.h" 87 | "valarraygen.h" 88 | "valarray.h" 89 | "vectorgen.h" 90 | "wstringlist.h" 91 | ) 92 | 93 | add_library(ccl SHARED ${CCL_SOURCES}) 94 | set_target_properties(ccl 95 | PROPERTIES 96 | SOVERSION ${VERSION_MAJOR} 97 | VERSION ${VERSION_STRING} 98 | ) 99 | 100 | install(TARGETS ccl 101 | RUNTIME DESTINATION bin 102 | LIBRARY DESTINATION lib 103 | ARCHIVE DESTINATION lib 104 | ) 105 | 106 | install(FILES ${CCL_HEADERS} DESTINATION "include/ccl") 107 | -------------------------------------------------------------------------------- /Makefile.lcc: -------------------------------------------------------------------------------- 1 | # Wedit Makefile for project ansicStl 2 | SRCDIR=. 3 | CFLAGS=-I. -O -A -p6 -ansic -g2 4 | CC=lcc.exe 5 | LINKER=lcclnk.exe 6 | HEADERS=containers.h ccl_internal.h valarray.h valarraygen.h 7 | OBJS=\ 8 | buffer.obj \ 9 | vector.obj \ 10 | bitstrings.obj \ 11 | bloom.obj \ 12 | error.obj \ 13 | deque.obj \ 14 | doublelist.obj \ 15 | dictionary.obj \ 16 | dlist.obj \ 17 | fgetline.obj \ 18 | generic.obj \ 19 | hashtable.obj \ 20 | heap.obj \ 21 | iMask.obj \ 22 | intlist.obj \ 23 | list.obj \ 24 | longlonglist.obj \ 25 | malloc_debug.obj \ 26 | pool.obj \ 27 | pooldebug.obj \ 28 | qsortex.obj \ 29 | queue.obj \ 30 | redblacktree.obj \ 31 | scapegoat.obj \ 32 | searchtree.obj \ 33 | strcollection.obj \ 34 | valarraydouble.obj \ 35 | valarrayint.obj \ 36 | valarrayuint.obj \ 37 | valarraysize_t.obj \ 38 | valarrayfloat.obj \ 39 | valarraylongdouble.obj \ 40 | valarrayuint.obj \ 41 | valarraylonglong.obj \ 42 | valarrayulonglong.obj \ 43 | valarrayshort.obj \ 44 | observer.obj \ 45 | memorymanager.obj \ 46 | priorityqueue.obj \ 47 | sequential.obj \ 48 | wstrcollection.obj \ 49 | 50 | LIST_GENERIC=listgen.c listgen.h 51 | 52 | EXE=dotest.exe 53 | 54 | LIBS=ccl.lib 55 | 56 | $(EXE): $(OBJS) Makefile test.obj ccl.lib 57 | $(LINKER) -subsystem console -o $(EXE) test.obj $(LIBS) 58 | 59 | ccl.lib: $(OBJS) 60 | lcclib /out:ccl.lib $(OBJS) 61 | 62 | # Build arraylist.c 63 | arraylist.obj: $(HEADERS) $(SRCDIR)\arraylist.c $(HEADERS) 64 | $(CC) -c $(CFLAGS) $(SRCDIR)\arraylist.c 65 | 66 | # Build bitstrings.c 67 | 68 | bitstrings.obj: $(HEADERS) $(SRCDIR)\bitstrings.c $(HEADERS) 69 | $(CC) -c $(CFLAGS) $(SRCDIR)\bitstrings.c 70 | 71 | bloom.obj: $(HEADERS) $(SRCDIR)\bloom.c $(HEADERS) 72 | $(CC) -c $(CFLAGS) $(SRCDIR)\bloom.c 73 | 74 | error.obj: $(HEADERS) $(SRCDIR)\error.c $(HEADERS) 75 | $(CC) -c $(CFLAGS) $(SRCDIR)\error.c 76 | 77 | # Build deque.c 78 | deque.obj: $(HEADERS) $(SRCDIR)\deque.c $(HEADERS) 79 | $(CC) -c $(CFLAGS) $(SRCDIR)\deque.c 80 | 81 | dictionary.obj: $(HEADERS) $(SRCDIR)\dictionary.c $(HEADERS) 82 | $(CC) -c $(CFLAGS) $(SRCDIR)\dictionary.c 83 | 84 | dlist.obj: $(HEADERS) $(SRCDIR)\dlist.c $(HEADERS) 85 | $(CC) -c $(CFLAGS) $(SRCDIR)\dlist.c 86 | 87 | fgetline.obj: $(HEADERS) $(SRCDIR)\fgetline.c $(HEADERS) 88 | $(CC) -c $(CFLAGS) $(SRCDIR)\fgetline.c 89 | 90 | generic.obj: $(HEADERS) generic.c $(HEADERS) 91 | $(CC) -c $(CFLAGS) $(SRCDIR)\generic.c 92 | 93 | hashtable.obj: $(HEADERS) $(SRCDIR)\hashtable.c $(HEADERS) 94 | $(CC) -c $(CFLAGS) $(SRCDIR)\hashtable.c 95 | 96 | heap.obj: $(HEADERS) $(SRCDIR)\heap.c $(HEADERS) 97 | $(CC) -c $(CFLAGS) $(SRCDIR)\heap.c 98 | 99 | # Build list.c 100 | LIST_C= $(HEADERS) 101 | 102 | list.obj: $(LIST_C) $(SRCDIR)\list.c 103 | $(CC) -c $(CFLAGS) $(SRCDIR)\list.c 104 | 105 | # Build malloc_debug.c 106 | MALLOC_DEBUG_C= $(HEADERS) 107 | 108 | malloc_debug.obj: $(SRCDIR)\malloc_debug.c $(HEADERS) 109 | $(CC) -c $(CFLAGS) $(SRCDIR)\malloc_debug.c 110 | 111 | # Build pool.c 112 | 113 | pool.obj: $(SRCDIR)\pool.c $(HEADERS) 114 | $(CC) -c $(CFLAGS) $(SRCDIR)\pool.c 115 | 116 | # Build pooldebug.c 117 | 118 | pooldebug.obj: $(SRCDIR)\pooldebug.c $(HEADERS) 119 | $(CC) -c $(CFLAGS) $(SRCDIR)\pooldebug.c 120 | 121 | # Build qsortex.c 122 | 123 | qsortex.obj: $(SRCDIR)\qsortex.c $(HEADERS) 124 | $(CC) -c $(CFLAGS) $(SRCDIR)\qsortex.c 125 | 126 | # Build redblacktree.c 127 | 128 | redblacktree.obj: $(SRCDIR)\redblacktree.c $(HEADERS) 129 | $(CC) -c $(CFLAGS) $(SRCDIR)\redblacktree.c 130 | 131 | # Build scapegoat.c 132 | 133 | scapegoat.obj: $(HEADERS) $(SRCDIR)\scapegoat.c $(HEADERS) 134 | $(CC) -c $(CFLAGS) $(SRCDIR)\scapegoat.c 135 | 136 | # Build searchtree.c 137 | 138 | searchtree.obj: $(HEADERS) $(SRCDIR)\searchtree.c $(HEADERS) 139 | $(CC) -c $(CFLAGS) $(SRCDIR)\searchtree.c 140 | 141 | # Build strcollection.c 142 | 143 | strcollection.obj: $(HEADERS) $(SRCDIR)\strcollection.c strcollectiongen.c $(HEADERS) 144 | $(CC) -c $(CFLAGS) $(SRCDIR)\strcollection.c 145 | 146 | queue.obj: $(SRCDIR)\containers.h queue.c $(HEADERS) 147 | $(CC) $(CFLAGS) queue.c 148 | 149 | 150 | valarrayint.obj: valarrayint.c valarraygen.c $(HEADERS) 151 | $(CC) -c $(CFLAGS) $(SRCDIR)\valarrayint.c 152 | 153 | valarrayuint.obj: valarrayuint.c valarraygen.c $(HEADERS) 154 | $(CC) -c $(CFLAGS) $(SRCDIR)\valarrayuint.c 155 | 156 | valarrayfloat.obj: valarrayfloat.c valarraygen.c $(HEADERS) 157 | $(CC) -c $(CFLAGS) $(SRCDIR)\valarrayfloat.c 158 | 159 | valarraydouble.obj: valarraydouble.c valarraygen.c $(HEADERS) 160 | $(CC) -c $(CFLAGS) $(SRCDIR)\valarraydouble.c 161 | 162 | valarraylongdouble.obj: valarraylongdouble.c valarraygen.c $(HEADERS) 163 | $(CC) -c $(CFLAGS) $(SRCDIR)\valarraylongdouble.c 164 | 165 | ort.obj: valarrayshort.c valarraygen.c valarray.h $(HEADERS) 166 | $(CC) -c $(CFLAGS) $(SRCDIR)\ort.c 167 | 168 | valarraysize_t.obj: valarraysize_t.c valarraygen.c $(HEADERS) 169 | $(CC) -c $(CFLAGS) $(SRCDIR)\valarraysize_t.c 170 | 171 | valarrayulonglong.obj: valarrayulonglong.c valarraygen.c $(HEADERS) 172 | $(CC) -c $(CFLAGS) $(SRCDIR)\valarrayulonglong.c 173 | 174 | sequential.obj: sequential.c $(HEADERS) 175 | $(CC) $(CFLAGS) $(SRCDIR)\sequential.c 176 | 177 | memorymanager.obj: $(HEADERS) memorymanager.c 178 | $(CC) $(CFLAGS) $(SRCDIR)\memorymanager.c 179 | 180 | intarray.obj: $(HEADERS) intarray.c 181 | $(CC) $(CFLAGS) $(SRCDIR)\intarray.c 182 | 183 | iMask.obj: iMask.c $(HEADERS) 184 | $(CC) $(CFLAGS) iMask.c 185 | 186 | wstrcollection.obj: wstrcollection.c strcollectiongen.c containers.h ccl_internal.h 187 | $(CC) $(CFLAGS) wstrcollection.c 188 | 189 | test.obj: $(TEST_C) $(SRCDIR)\test.c $(HEADERS) 190 | $(CC) -c $(CFLAGS) $(SRCDIR)\test.c 191 | intlist.obj: intlist.c intlist.h ccl_internal.h containers.h $(LIST_GENERIC) 192 | 193 | link: 194 | $(LINKER) -subsystem console -o $(SRCDIR)\lcc\ansicstl.exe $(OBJS) $(LIBS) 195 | 196 | clean: 197 | del $(OBJS) dotest.exe ccl.lib 198 | -------------------------------------------------------------------------------- /Makefile.lcc64: -------------------------------------------------------------------------------- 1 | # Wedit Makefile for project ansicStl 2 | SRCDIR=. 3 | #CFLAGS=-I. -O -A -p6 -ansic -g2 4 | # Change below lcc64 to have a 64 bit version 5 | CC=lcc64.exe 6 | CFLAGS= -I. -O -ansic -g2 7 | LINKER=lcclnk64.exe 8 | HEADERS=containers.h ccl_internal.h valarray.h valarraygen.h 9 | OBJS=\ 10 | buffer.obj \ 11 | vector.obj \ 12 | bitstrings.obj \ 13 | bloom.obj \ 14 | error.obj \ 15 | deque.obj \ 16 | dictionary.obj \ 17 | doublelist.obj \ 18 | dlist.obj \ 19 | fgetline.obj \ 20 | generic.obj \ 21 | hashtable.obj \ 22 | heap.obj \ 23 | iMask.obj \ 24 | intlist.obj \ 25 | list.obj \ 26 | longlonglist.obj \ 27 | malloc_debug.obj \ 28 | pool.obj \ 29 | pooldebug.obj \ 30 | qsortex.obj \ 31 | queue.obj \ 32 | redblacktree.obj \ 33 | scapegoat.obj \ 34 | searchtree.obj \ 35 | strcollection.obj \ 36 | valarraydouble.obj \ 37 | valarrayint.obj \ 38 | valarrayuint.obj \ 39 | valarraysize_t.obj \ 40 | valarrayfloat.obj \ 41 | valarraylongdouble.obj \ 42 | valarrayuint.obj \ 43 | valarraylonglong.obj \ 44 | valarrayulonglong.obj \ 45 | valarrayshort.obj \ 46 | vectorsize_t.obj \ 47 | observer.obj \ 48 | memorymanager.obj \ 49 | sequential.obj \ 50 | wstrcollection.obj \ 51 | 52 | EXE=dotest.exe 53 | 54 | LIBS=ccl64.lib 55 | 56 | $(EXE): $(OBJS) Makefile test.obj ccl64.lib 57 | $(LINKER) -subsystem console -o $(EXE) test.obj $(LIBS) 58 | 59 | ccl64.lib: $(OBJS) 60 | lcclib /out:ccl64.lib $(OBJS) 61 | 62 | # Build arraylist.c 63 | arraylist.obj: $(HEADERS) $(SRCDIR)\arraylist.c $(HEADERS) 64 | $(CC) -c $(CFLAGS) $(SRCDIR)\arraylist.c 65 | 66 | # Build bitstrings.c 67 | 68 | bitstrings.obj: $(HEADERS) $(SRCDIR)\bitstrings.c $(HEADERS) 69 | $(CC) -c $(CFLAGS) $(SRCDIR)\bitstrings.c 70 | 71 | bloom.obj: $(HEADERS) $(SRCDIR)\bloom.c $(HEADERS) 72 | $(CC) -c $(CFLAGS) $(SRCDIR)\bloom.c 73 | 74 | error.obj: $(HEADERS) $(SRCDIR)\error.c $(HEADERS) 75 | $(CC) -c $(CFLAGS) $(SRCDIR)\error.c 76 | 77 | # Build deque.c 78 | deque.obj: $(HEADERS) $(SRCDIR)\deque.c $(HEADERS) 79 | $(CC) -c $(CFLAGS) $(SRCDIR)\deque.c 80 | 81 | dictionary.obj: $(HEADERS) $(SRCDIR)\dictionary.c $(HEADERS) 82 | $(CC) -c $(CFLAGS) $(SRCDIR)\dictionary.c 83 | 84 | dlist.obj: $(HEADERS) $(SRCDIR)\dlist.c $(HEADERS) 85 | $(CC) -c $(CFLAGS) $(SRCDIR)\dlist.c 86 | 87 | fgetline.obj: $(HEADERS) $(SRCDIR)\fgetline.c $(HEADERS) 88 | $(CC) -c $(CFLAGS) $(SRCDIR)\fgetline.c 89 | 90 | generic.obj: $(HEADERS) generic.c $(HEADERS) 91 | $(CC) -c $(CFLAGS) $(SRCDIR)\generic.c 92 | 93 | hashtable.obj: $(HEADERS) $(SRCDIR)\hashtable.c $(HEADERS) 94 | $(CC) -c $(CFLAGS) $(SRCDIR)\hashtable.c 95 | 96 | heap.obj: $(HEADERS) $(SRCDIR)\heap.c $(HEADERS) 97 | $(CC) -c $(CFLAGS) $(SRCDIR)\heap.c 98 | 99 | # Build list.c 100 | LIST_C= $(HEADERS) 101 | 102 | list.obj: $(LIST_C) $(SRCDIR)\list.c 103 | $(CC) -c $(CFLAGS) $(SRCDIR)\list.c 104 | 105 | # Build malloc_debug.c 106 | MALLOC_DEBUG_C= $(HEADERS) 107 | 108 | malloc_debug.obj: $(SRCDIR)\malloc_debug.c $(HEADERS) 109 | $(CC) -c $(CFLAGS) $(SRCDIR)\malloc_debug.c 110 | 111 | # Build pool.c 112 | 113 | pool.obj: $(SRCDIR)\pool.c $(HEADERS) 114 | $(CC) -c $(CFLAGS) $(SRCDIR)\pool.c 115 | 116 | # Build pooldebug.c 117 | 118 | pooldebug.obj: $(SRCDIR)\pooldebug.c $(HEADERS) 119 | $(CC) -c $(CFLAGS) $(SRCDIR)\pooldebug.c 120 | 121 | # Build qsortex.c 122 | 123 | qsortex.obj: $(SRCDIR)\qsortex.c $(HEADERS) 124 | $(CC) -c $(CFLAGS) $(SRCDIR)\qsortex.c 125 | 126 | # Build redblacktree.c 127 | 128 | redblacktree.obj: $(SRCDIR)\redblacktree.c $(HEADERS) 129 | $(CC) -c $(CFLAGS) $(SRCDIR)\redblacktree.c 130 | 131 | # Build scapegoat.c 132 | 133 | scapegoat.obj: $(HEADERS) $(SRCDIR)\scapegoat.c $(HEADERS) 134 | $(CC) -c $(CFLAGS) $(SRCDIR)\scapegoat.c 135 | 136 | # Build searchtree.c 137 | 138 | searchtree.obj: $(HEADERS) $(SRCDIR)\searchtree.c $(HEADERS) 139 | $(CC) -c $(CFLAGS) $(SRCDIR)\searchtree.c 140 | 141 | # Build strcollection.c 142 | 143 | strcollection.obj: $(HEADERS) $(SRCDIR)\strcollection.c strcollectiongen.c $(HEADERS) 144 | $(CC) -c $(CFLAGS) $(SRCDIR)\strcollection.c 145 | 146 | queue.obj: $(SRCDIR)\containers.h queue.c $(HEADERS) 147 | $(CC) $(CFLAGS) queue.c 148 | 149 | 150 | valarrayint.obj: valarrayint.c valarraygen.c $(HEADERS) 151 | $(CC) -c $(CFLAGS) $(SRCDIR)\valarrayint.c 152 | 153 | valarrayuint.obj: valarrayuint.c valarraygen.c $(HEADERS) 154 | $(CC) -c $(CFLAGS) $(SRCDIR)\valarrayuint.c 155 | 156 | valarrayfloat.obj: valarrayfloat.c valarraygen.c $(HEADERS) 157 | $(CC) -c $(CFLAGS) $(SRCDIR)\valarrayfloat.c 158 | 159 | valarraydouble.obj: valarraydouble.c valarraygen.c $(HEADERS) 160 | $(CC) -c $(CFLAGS) $(SRCDIR)\valarraydouble.c 161 | 162 | valarraylongdouble.obj: valarraylongdouble.c valarraygen.c $(HEADERS) 163 | $(CC) -c $(CFLAGS) $(SRCDIR)\valarraylongdouble.c 164 | 165 | ort.obj: valarrayshort.c valarraygen.c valarray.h $(HEADERS) 166 | $(CC) -c $(CFLAGS) $(SRCDIR)\ort.c 167 | 168 | valarraysize_t.obj: valarraysize_t.c valarraygen.c $(HEADERS) 169 | $(CC) -c $(CFLAGS) $(SRCDIR)\valarraysize_t.c 170 | 171 | valarrayulonglong.obj: valarrayulonglong.c valarraygen.c $(HEADERS) 172 | $(CC) -c $(CFLAGS) $(SRCDIR)\valarrayulonglong.c 173 | 174 | sequential.obj: sequential.c $(HEADERS) 175 | $(CC) $(CFLAGS) $(SRCDIR)\sequential.c 176 | 177 | memorymanager.obj: $(HEADERS) memorymanager.c 178 | $(CC) $(CFLAGS) $(SRCDIR)\memorymanager.c 179 | 180 | intarray.obj: $(HEADERS) intarray.c 181 | $(CC) $(CFLAGS) $(SRCDIR)\intarray.c 182 | 183 | iMask.obj: iMask.c $(HEADERS) 184 | $(CC) $(CFLAGS) iMask.c 185 | 186 | wstrcollection.obj: wstrcollection.c strcollectiongen.c containers.h ccl_internal.h 187 | $(CC) $(CFLAGS) wstrcollection.c 188 | 189 | intlist.obj: intlist.c intlist.h ccl_internal.h containers.h $(LIST_GENERIC) 190 | $(CC) $(CFLAGS) intlist.c 191 | 192 | doublelist.obj: doublelist.c doublelist.h ccl_internal.h containers.h $(LIST_GENERIC) 193 | $(CC) $(CFLAGS) doublelist.c 194 | 195 | longlonglist.obj: longlonglist.c longlonglist.h ccl_internal.h containers.h $(LIST_GENERIC) 196 | $(CC) $(CFLAGS) longlonglist.c 197 | 198 | 199 | vectorsize_t.obj: vectorsize_t.c vectorgen.h vectorgen.c containers.h ccl_internals.h 200 | $(CC) $(CFLAGS) $(SRCDIR)\vectorsize_t.c 201 | 202 | test.obj: $(TEST_C) $(SRCDIR)\test.c $(HEADERS) 203 | $(CC) -c $(CFLAGS) $(SRCDIR)\test.c 204 | 205 | link: 206 | $(LINKER) -subsystem console -o $(SRCDIR)\lcc\ansicstl.exe $(OBJS) $(LIBS) 207 | 208 | clean: 209 | del $(OBJS) dotest.exe ccl64.lib 210 | -------------------------------------------------------------------------------- /Makefile.msvc: -------------------------------------------------------------------------------- 1 | # Wedit Makefile for project ansicStl 2 | SRCDIR=. 3 | CFLAGS=-I. -Zi -W4 -D_CRT_SECURE_NO_WARNINGS -c 4 | CC=cl.exe 5 | LINKER=link.exe 6 | OBJS=\ 7 | vector.obj \ 8 | bitstrings.obj \ 9 | bloom.obj \ 10 | error.obj \ 11 | deque.obj \ 12 | dictionary.obj \ 13 | dlist.obj \ 14 | fgetline.obj \ 15 | generic.obj \ 16 | hashtable.obj \ 17 | heap.obj \ 18 | iMask.obj \ 19 | list.obj \ 20 | malloc_debug.obj \ 21 | pool.obj \ 22 | pooldebug.obj \ 23 | qsortex.obj \ 24 | queue.obj \ 25 | redblacktree.obj \ 26 | scapegoat.obj \ 27 | searchtree.obj \ 28 | strcollection.obj \ 29 | observer.obj \ 30 | valarrayuint.obj \ 31 | valarrayint.obj \ 32 | valarrayfloat.obj \ 33 | valarraydouble.obj \ 34 | valarraylongdouble.obj \ 35 | valarraylonglong.obj \ 36 | valarrayshort.obj \ 37 | valarraysize_t.obj \ 38 | memorymanager.obj \ 39 | sequential.obj \ 40 | buffer.obj 41 | 42 | EXE=dotest.exe 43 | LIBS=cclmsvc.lib 44 | 45 | $(EXE): $(OBJS) Makefile tlist.obj cclmsvc.lib 46 | $(LINKER) /debug tlist.obj $(LIBS) 47 | 48 | cclmsvc.lib: $(OBJS) 49 | lib /out:cclmsvc.lib $(OBJS) 50 | 51 | valarraylongdouble.obj: valarraygen.c valarraylongdouble.c containers.h valarraygen.h valarray.h 52 | $(CC) -c $(CFLAGS) $(SRCDIR)\valarraylongdouble.c 53 | 54 | valarraydouble.o: valarraygen.c valarraydouble.c containers.h valarraygen.h valarray.h 55 | $(CC) -c $(CFLAGS) $(SRCDIR)\valarraydouble.c 56 | 57 | valarrayint.obj: valarraygen.c valarrayint.c containers.h valarraygen.h valarray.h 58 | $(CC) -c $(CFLAGS) $(SRCDIR)\valarrayint.c 59 | 60 | valarrayshort.obj: valarraygen.c valarrayshort.c containers.h valarraygen.h valarray.h 61 | $(CC) -c $(CFLAGS) $(SRCDIR)\valarrayshort.c 62 | 63 | valarraysize_t.obj: valarraygen.c valarraysize_t.c containers.h valarraygen.h valarray.h 64 | $(CC) -c $(CFLAGS) $(SRCDIR)\valarraysize_t.c 65 | 66 | valarrayfloat.obj: valarraygen.c valarrayfloat.c containers.h valarraygen.h valarray.h 67 | $(CC) -c $(CFLAGS) $(SRCDIR)\valarrayfloat.c 68 | 69 | valarrayuint.obj: valarraygen.c valarrayuint.c containers.h valarraygen.h valarray.h 70 | $(CC) -c $(CFLAGS) $(SRCDIR)\valarrayuint.c 71 | 72 | valarraylonglong.obj: valarraygen.c valarraylonglong.c containers.h valarraygen.h valarray.h 73 | $(CC) -c $(CFLAGS) $(SRCDIR)\valarraylonglong.c 74 | generic.obj: generic.c containers.h 75 | $(CC) $(CFLAGS) $(SRCDIR)\generic.c 76 | 77 | # Build vector.c 78 | ARRAYLIST_C=\ 79 | $(SRCDIR)\containers.h\ 80 | C:\lcc\include\string.h\ 81 | C:\lcc\include\stddef.h\ 82 | C:\lcc\include\stdlib.h\ 83 | C:\lcc\include\stddef.h\ 84 | C:\lcc\include\stdio.h\ 85 | C:\lcc\include\safelib.h\ 86 | C:\lcc\include\stdint.h\ 87 | C:\lcc\include\limits.h\ 88 | 89 | vector.obj: $(ARRAYLIST_C) $(SRCDIR)\vector.c 90 | $(CC) -c $(CFLAGS) $(SRCDIR)\vector.c 91 | 92 | # Build bitstrings.c 93 | BITSTRINGS_C=\ 94 | C:\lcc\include\stdio.h\ 95 | C:\lcc\include\safelib.h\ 96 | C:\lcc\include\string.h\ 97 | C:\lcc\include\limits.h\ 98 | C:\lcc\include\stddef.h\ 99 | C:\lcc\include\stdlib.h\ 100 | C:\lcc\include\stddef.h\ 101 | C:\lcc\include\string.h\ 102 | $(SRCDIR)\containers.h\ 103 | C:\lcc\include\string.h\ 104 | C:\lcc\include\stddef.h\ 105 | C:\lcc\include\stdlib.h\ 106 | C:\lcc\include\stdio.h\ 107 | C:\lcc\include\stdint.h\ 108 | C:\lcc\include\limits.h\ 109 | 110 | bitstrings.obj: $(BITSTRINGS_C) $(SRCDIR)\bitstrings.c 111 | $(CC) -c $(CFLAGS) $(SRCDIR)\bitstrings.c 112 | 113 | # Build bloom.c 114 | BLOOM_C=\ 115 | C:\lcc\include\math.h\ 116 | C:\lcc\include\stdlib.h\ 117 | C:\lcc\include\stddef.h\ 118 | C:\lcc\include\stdio.h\ 119 | C:\lcc\include\safelib.h\ 120 | $(SRCDIR)\containers.h\ 121 | C:\lcc\include\string.h\ 122 | C:\lcc\include\stddef.h\ 123 | C:\lcc\include\stdlib.h\ 124 | C:\lcc\include\stdio.h\ 125 | C:\lcc\include\stdint.h\ 126 | C:\lcc\include\limits.h\ 127 | 128 | bloom.obj: $(BLOOM_C) $(SRCDIR)\bloom.c 129 | $(CC) -c $(CFLAGS) $(SRCDIR)\bloom.c 130 | 131 | # Build error.c 132 | CONTAINERERROR_C=\ 133 | $(SRCDIR)\containers.h\ 134 | C:\lcc\include\string.h\ 135 | C:\lcc\include\stddef.h\ 136 | C:\lcc\include\stdlib.h\ 137 | C:\lcc\include\stddef.h\ 138 | C:\lcc\include\stdio.h\ 139 | C:\lcc\include\safelib.h\ 140 | C:\lcc\include\stdint.h\ 141 | C:\lcc\include\limits.h\ 142 | C:\lcc\include\stdio.h\ 143 | 144 | error.obj: $(CONTAINERERROR_C) $(SRCDIR)\error.c 145 | $(CC) -c $(CFLAGS) $(SRCDIR)\error.c 146 | 147 | # Build deque.c 148 | DEQUE_C=\ 149 | C:\lcc\include\string.h\ 150 | C:\lcc\include\assert.h\ 151 | $(SRCDIR)\containers.h\ 152 | C:\lcc\include\string.h\ 153 | C:\lcc\include\stddef.h\ 154 | C:\lcc\include\stdlib.h\ 155 | C:\lcc\include\stddef.h\ 156 | C:\lcc\include\stdio.h\ 157 | C:\lcc\include\safelib.h\ 158 | C:\lcc\include\stdint.h\ 159 | C:\lcc\include\limits.h\ 160 | 161 | deque.obj: $(DEQUE_C) $(SRCDIR)\deque.c 162 | $(CC) -c $(CFLAGS) $(SRCDIR)\deque.c 163 | 164 | # Build dictionary.c 165 | DICTIONARY_C=\ 166 | C:\lcc\include\limits.h\ 167 | C:\lcc\include\stddef.h\ 168 | $(SRCDIR)\containers.h\ 169 | C:\lcc\include\string.h\ 170 | C:\lcc\include\stddef.h\ 171 | C:\lcc\include\stdlib.h\ 172 | C:\lcc\include\stddef.h\ 173 | C:\lcc\include\stdio.h\ 174 | C:\lcc\include\safelib.h\ 175 | C:\lcc\include\stdint.h\ 176 | C:\lcc\include\limits.h\ 177 | C:\lcc\include\assert.h\ 178 | 179 | dictionary.obj: $(DICTIONARY_C) $(SRCDIR)\dictionary.c 180 | $(CC) -c $(CFLAGS) $(SRCDIR)\dictionary.c 181 | 182 | # Build dlist.c 183 | DLIST_C=\ 184 | $(SRCDIR)\containers.h\ 185 | C:\lcc\include\string.h\ 186 | C:\lcc\include\stddef.h\ 187 | C:\lcc\include\stdlib.h\ 188 | C:\lcc\include\stddef.h\ 189 | C:\lcc\include\stdio.h\ 190 | C:\lcc\include\safelib.h\ 191 | C:\lcc\include\stdint.h\ 192 | C:\lcc\include\limits.h\ 193 | 194 | dlist.obj: $(DLIST_C) $(SRCDIR)\dlist.c 195 | $(CC) -c $(CFLAGS) $(SRCDIR)\dlist.c 196 | 197 | # Build fgetline.c 198 | FGETLINE_C=\ 199 | C:\lcc\include\stdio.h\ 200 | C:\lcc\include\safelib.h\ 201 | C:\lcc\include\stdlib.h\ 202 | C:\lcc\include\stddef.h\ 203 | C:\lcc\include\limits.h\ 204 | $(SRCDIR)\containers.h\ 205 | C:\lcc\include\string.h\ 206 | C:\lcc\include\stddef.h\ 207 | C:\lcc\include\stdlib.h\ 208 | C:\lcc\include\stdio.h\ 209 | C:\lcc\include\stdint.h\ 210 | C:\lcc\include\limits.h\ 211 | 212 | fgetline.obj: $(FGETLINE_C) $(SRCDIR)\fgetline.c 213 | $(CC) -c $(CFLAGS) $(SRCDIR)\fgetline.c 214 | 215 | # Build hashtable.c 216 | HASHTABLE_C=\ 217 | $(SRCDIR)\containers.h\ 218 | C:\lcc\include\string.h\ 219 | C:\lcc\include\stddef.h\ 220 | C:\lcc\include\stdlib.h\ 221 | C:\lcc\include\stddef.h\ 222 | C:\lcc\include\stdio.h\ 223 | C:\lcc\include\safelib.h\ 224 | C:\lcc\include\stdint.h\ 225 | C:\lcc\include\limits.h\ 226 | 227 | hashtable.obj: $(HASHTABLE_C) $(SRCDIR)\hashtable.c 228 | $(CC) -c $(CFLAGS) $(SRCDIR)\hashtable.c 229 | 230 | # Build heap.c 231 | HEAP_C=\ 232 | $(SRCDIR)\containers.h\ 233 | C:\lcc\include\string.h\ 234 | C:\lcc\include\stddef.h\ 235 | C:\lcc\include\stdlib.h\ 236 | C:\lcc\include\stddef.h\ 237 | C:\lcc\include\stdio.h\ 238 | C:\lcc\include\safelib.h\ 239 | C:\lcc\include\stdint.h\ 240 | C:\lcc\include\limits.h\ 241 | 242 | heap.obj: $(HEAP_C) $(SRCDIR)\heap.c 243 | $(CC) -c $(CFLAGS) $(SRCDIR)\heap.c 244 | 245 | # Build list.c 246 | LIST_C=\ 247 | $(SRCDIR)\containers.h\ 248 | C:\lcc\include\string.h\ 249 | C:\lcc\include\stddef.h\ 250 | C:\lcc\include\stdlib.h\ 251 | C:\lcc\include\stddef.h\ 252 | C:\lcc\include\stdio.h\ 253 | C:\lcc\include\safelib.h\ 254 | C:\lcc\include\stdint.h\ 255 | C:\lcc\include\limits.h\ 256 | 257 | list.obj: $(LIST_C) $(SRCDIR)\list.c 258 | $(CC) -c $(CFLAGS) $(SRCDIR)\list.c 259 | 260 | # Build malloc_debug.c 261 | MALLOC_DEBUG_C=\ 262 | $(SRCDIR)\containers.h\ 263 | C:\lcc\include\string.h\ 264 | C:\lcc\include\stddef.h\ 265 | C:\lcc\include\stdlib.h\ 266 | C:\lcc\include\stddef.h\ 267 | C:\lcc\include\stdio.h\ 268 | C:\lcc\include\safelib.h\ 269 | C:\lcc\include\stdint.h\ 270 | C:\lcc\include\limits.h\ 271 | 272 | malloc_debug.obj: $(MALLOC_DEBUG_C) $(SRCDIR)\malloc_debug.c 273 | $(CC) -c $(CFLAGS) $(SRCDIR)\malloc_debug.c 274 | 275 | # Build pool.c 276 | POOL_C=\ 277 | C:\lcc\include\inttypes.h\ 278 | C:\lcc\include\stdint.h\ 279 | $(SRCDIR)\containers.h\ 280 | C:\lcc\include\string.h\ 281 | C:\lcc\include\stddef.h\ 282 | C:\lcc\include\stdlib.h\ 283 | C:\lcc\include\stddef.h\ 284 | C:\lcc\include\stdio.h\ 285 | C:\lcc\include\safelib.h\ 286 | C:\lcc\include\stdint.h\ 287 | C:\lcc\include\limits.h\ 288 | 289 | pool.obj: $(POOL_C) $(SRCDIR)\pool.c 290 | $(CC) -c $(CFLAGS) $(SRCDIR)\pool.c 291 | 292 | # Build pooldebug.c 293 | POOLDEBUG_C=\ 294 | $(SRCDIR)\containers.h\ 295 | C:\lcc\include\string.h\ 296 | C:\lcc\include\stddef.h\ 297 | C:\lcc\include\stdlib.h\ 298 | C:\lcc\include\stddef.h\ 299 | C:\lcc\include\stdio.h\ 300 | C:\lcc\include\safelib.h\ 301 | C:\lcc\include\stdint.h\ 302 | C:\lcc\include\limits.h\ 303 | C:\lcc\include\inttypes.h\ 304 | C:\lcc\include\stdint.h\ 305 | C:\lcc\include\stdio.h\ 306 | 307 | pooldebug.obj: $(POOLDEBUG_C) $(SRCDIR)\pooldebug.c 308 | $(CC) -c $(CFLAGS) $(SRCDIR)\pooldebug.c 309 | 310 | # Build qsortex.c 311 | QSORTEX_C=\ 312 | C:\lcc\include\errno.h\ 313 | C:\lcc\include\string.h\ 314 | C:\lcc\include\stdlib.h\ 315 | C:\lcc\include\stddef.h\ 316 | $(SRCDIR)\containers.h\ 317 | C:\lcc\include\string.h\ 318 | C:\lcc\include\stddef.h\ 319 | C:\lcc\include\stdlib.h\ 320 | C:\lcc\include\stdio.h\ 321 | C:\lcc\include\safelib.h\ 322 | C:\lcc\include\stdint.h\ 323 | C:\lcc\include\limits.h\ 324 | 325 | qsortex.obj: $(QSORTEX_C) $(SRCDIR)\qsortex.c 326 | $(CC) -c $(CFLAGS) $(SRCDIR)\qsortex.c 327 | 328 | # Build redblacktree.c 329 | REDBLACKTREE_C=\ 330 | C:\lcc\include\stdio.h\ 331 | C:\lcc\include\safelib.h\ 332 | C:\lcc\include\stdlib.h\ 333 | C:\lcc\include\stddef.h\ 334 | $(SRCDIR)\containers.h\ 335 | C:\lcc\include\string.h\ 336 | C:\lcc\include\stddef.h\ 337 | C:\lcc\include\stdlib.h\ 338 | C:\lcc\include\stdio.h\ 339 | C:\lcc\include\stdint.h\ 340 | C:\lcc\include\limits.h\ 341 | $(SRCDIR)\containers.h\ 342 | 343 | redblacktree.obj: $(REDBLACKTREE_C) $(SRCDIR)\redblacktree.c 344 | $(CC) -c $(CFLAGS) $(SRCDIR)\redblacktree.c 345 | 346 | # Build scapegoat.c 347 | SCAPEGOAT_C=\ 348 | C:\lcc\include\stdio.h\ 349 | C:\lcc\include\safelib.h\ 350 | C:\lcc\include\stdlib.h\ 351 | C:\lcc\include\stddef.h\ 352 | $(SRCDIR)\containers.h\ 353 | C:\lcc\include\string.h\ 354 | C:\lcc\include\stddef.h\ 355 | C:\lcc\include\stdlib.h\ 356 | C:\lcc\include\stdio.h\ 357 | C:\lcc\include\stdint.h\ 358 | C:\lcc\include\limits.h\ 359 | $(SRCDIR)\containers.h\ 360 | 361 | scapegoat.obj: $(SCAPEGOAT_C) $(SRCDIR)\scapegoat.c 362 | $(CC) -c $(CFLAGS) $(SRCDIR)\scapegoat.c 363 | 364 | # Build searchtree.c 365 | SEARCHTREE_C=\ 366 | C:\lcc\include\stdlib.h\ 367 | C:\lcc\include\stddef.h\ 368 | C:\lcc\include\string.h\ 369 | C:\lcc\include\stdlib.h\ 370 | $(SRCDIR)\containers.h\ 371 | C:\lcc\include\string.h\ 372 | C:\lcc\include\stddef.h\ 373 | C:\lcc\include\stdlib.h\ 374 | C:\lcc\include\stdio.h\ 375 | C:\lcc\include\safelib.h\ 376 | C:\lcc\include\stdint.h\ 377 | C:\lcc\include\limits.h\ 378 | 379 | searchtree.obj: $(SEARCHTREE_C) $(SRCDIR)\searchtree.c 380 | $(CC) -c $(CFLAGS) $(SRCDIR)\searchtree.c 381 | 382 | # Build strcollection.c 383 | STRCOLLECTION_C=\ 384 | $(SRCDIR)\containers.h\ 385 | C:\lcc\include\string.h\ 386 | C:\lcc\include\stddef.h\ 387 | C:\lcc\include\stdlib.h\ 388 | C:\lcc\include\stddef.h\ 389 | C:\lcc\include\stdio.h\ 390 | C:\lcc\include\safelib.h\ 391 | C:\lcc\include\stdint.h\ 392 | C:\lcc\include\limits.h\ 393 | 394 | strcollection.obj: $(STRCOLLECTION_C) $(SRCDIR)\strcollection.c 395 | $(CC) -c $(CFLAGS) $(SRCDIR)\strcollection.c 396 | memorymanager.obj: memorymanager.c containers.h 397 | $(CC) $(CFLAGS) $(SRCDIR)\memorymanager.c 398 | sequential.obj: sequential.c containers.h 399 | $(CC) $(CFLAGS) $(SRCDIR)\sequential.c 400 | 401 | queue.obj: containers.h queue.c 402 | $(CC) -c $(CFLAGS) queue.c 403 | 404 | buffer.obj: buffer.c containers.h 405 | $(CC) -c $(CFLAGS) buffer.c 406 | observer.obj: observer.c containers.h 407 | $(CC) $(CFLAGS) observer.c 408 | iMask.obj: iMask.c containers.h 409 | $(CC) $(CFLAGS) iMask.c 410 | 411 | # Build test.c 412 | TEST_C=\ 413 | $(SRCDIR)\containers.h\ 414 | C:\lcc\include\string.h\ 415 | C:\lcc\include\stddef.h\ 416 | C:\lcc\include\stdlib.h\ 417 | C:\lcc\include\stddef.h\ 418 | C:\lcc\include\stdio.h\ 419 | C:\lcc\include\safelib.h\ 420 | C:\lcc\include\stdint.h\ 421 | C:\lcc\include\limits.h\ 422 | C:\lcc\include\stdio.h\ 423 | C:\lcc\include\stdio.h\ 424 | 425 | tlist.obj: $(TEST_C) $(SRCDIR)\tlist.c 426 | $(CC) -c $(CFLAGS) $(SRCDIR)\tlist.c 427 | 428 | 429 | link: 430 | $(LINKER) /out:test.exe $(OBJS) $(LIBS) 431 | 432 | clean: 433 | del $(OBJS) dotest.exe cclmsvc.lib 434 | -------------------------------------------------------------------------------- /Makefile.old: -------------------------------------------------------------------------------- 1 | #---------------------------------------------------- 2 | # UNIX makefile 3 | # Creates the library libccl.a and a small test program "dotest" 4 | # 5 | #--------------------------------------------------- 6 | # Optimized CFLAGS setting 7 | CFLAGS=-O2 -Wno-pointer-sign -DUNIX -Wall -D__MAC_OSX 8 | CC=gcc 9 | # Debug CFLAGS setting 10 | #CFLAGS=-Wno-pointer-sign -DUNIX -Wall -g 11 | SRC= vector.c bloom.c error.c dlist.c qsortex.c heap.c \ 12 | deque.c hashtable.c malloc_debug.c containers.h ccl_internal.h \ 13 | stdint.h.noc99 pool.c pooldebug.c redblacktree.c scapegoat.c smallpool.c ccl_internal.h \ 14 | bitstrings.c dictionarygen.c list.c memorymanager.c strcollection.c searchtree.c \ 15 | containers.h ccl_internal.h redblacktree.c fgetline.c generic.c queue.c buffer.c observer.c \ 16 | valarraydouble.c vectorsize_t.c valarrayint.c valarraylongdouble.c valarraygen.c \ 17 | valarrayshort.c valarrayfloat.c valarrayuint.c valarraylonglong.c \ 18 | valarrayulonglong.c sequential.c iMask.c wstrcollection.c strcollectiongen.c \ 19 | stringlistgen.c stringlistgen.h stringlist.c stringlist.h wstringlist.h \ 20 | priorityqueue.c intlist.c listgen.c 21 | DOCS= 22 | MAKEFILES=Makefile Makefile.lcc Makefile.msvc 23 | 24 | OBJS=vector.o error.o dlist.o qsortex.o bitstrings.o generic.o \ 25 | dictionary.o wdictionary.o list.o strcollection.o searchtree.o heap.o malloc_debug.o \ 26 | bloom.o fgetline.o pool.o pooldebug.o redblacktree.o scapegoat.o queue.o \ 27 | buffer.o observer.o valarraydouble.o valarrayint.o vectorsize_t.o \ 28 | valarraylongdouble.o valarrayshort.o valarrayfloat.o valarrayuint.o \ 29 | valarraylonglong.o valarrayulonglong.o memorymanager.o sequential.o \ 30 | iMask.o deque.o hashtable.o wstrcollection.o stringlist.o wstringlist.o \ 31 | priorityqueue.o intlist.o doublelist.o longlonglist.o intdlist.o \ 32 | doubledlist.o longlongdlist.o 33 | LIST_GENERIC=listgen.c listgen.h 34 | DLIST_GENERIC=dlistgen.c dlistgen.h 35 | #DRAWINGS 36 | PNGFILES=AuxiliaryInterfaces.png DListVocabulary.png Pool.png bitstrings.png Basic.png \ 37 | Dictionary.png StreamBuffer.png list.png BloomFilter.png Iterator.png ValArray.png \ 38 | Circular.png ListVocabulary.png VectorVocabulary.png Containers.png Memorymanagement.png\ 39 | Vocabulary.png 40 | #Documentation source files. Some of those are automatically generated 41 | TEXFILES=BitString.tex Dlist.tex PQueue.tex ValArray.tex \ 42 | ContainerHeap.tex HashTable.tex Queue.tex Vector.tex rgb.tex\ 43 | Deque.tex Introduction.tex StreamBuffer.tex WDictionary.tex strcollection.tex\ 44 | Dictionary.tex List.tex TreeMap.tex ccl.tex table.tex 45 | 46 | #----------------------------------IMPORTANT -------------------- 47 | #### 48 | #### Please remove ccl.pdf from the targets if you do not have the TeX system installed 49 | #### 50 | #-----------------------------------IMPORTANT -------------------- 51 | all: libccl.a dotest ccl.pdf 52 | dotest: libccl.a test.o 53 | gcc -o dotest -g $(CFLAGS) test.c libccl.a -lm 54 | libccl.a: $(OBJS) containers.h ccl_internal.h ccl_internal.h 55 | ar r libccl.a $(OBJS) 56 | clean: 57 | rm -rf $(OBJS) libccl.a dotest dotest.dSYM ccl.zip ccl.pdf ccl.log ccl.aux ccl.toc ccl.ilg 58 | zip: $(SRC) 59 | rm ccl.zip;rm -rf ccl;svn export . ccl;/bin/sh dolinks.sh;zip -9 -r ccl.zip ccl 60 | 61 | valarraylongdouble.o: valarraygen.c valarraylongdouble.c containers.h ccl_internal.h valarraygen.h valarray.h 62 | valarraydouble.o: valarraygen.c valarraydouble.c containers.h ccl_internal.h valarraygen.h valarray.h 63 | valarrayint.o: valarraygen.c valarrayint.c containers.h ccl_internal.h valarraygen.h valarray.h 64 | valarrayshort.o: valarraygen.c valarrayshort.c containers.h ccl_internal.h valarraygen.h valarray.h 65 | vectorsize_t.o: vectorgen.c vectorsize_t.c containers.h ccl_internal.h vectorgen.h 66 | valarrayfloat.o: valarraygen.c valarrayfloat.c containers.h ccl_internal.h valarraygen.h valarray.h 67 | valarrayuint.o: valarraygen.c valarrayuint.c containers.h ccl_internal.h valarraygen.h valarray.h 68 | valarraylonglong.o: valarraygen.c valarraylonglong.c containers.h ccl_internal.h valarraygen.h valarray.h 69 | valarrayulonglong.o: valarraygen.c valarrayulonglong.c containers.h ccl_internal.h valarraygen.h valarray.h 70 | observer.o: containers.h ccl_internal.h observer.c 71 | buffer.o: containers.h ccl_internal.h buffer.c 72 | vector.o: containers.h ccl_internal.h vector.c 73 | buffer.o: containers.h ccl_internal.h buffer.c 74 | vector.o: containers.h ccl_internal.h vector.c 75 | bloom.o: containers.h ccl_internal.h bloom.c 76 | error.o: containers.h ccl_internal.h error.c 77 | dlist.o: dlist.c containers.h ccl_internal.h 78 | deque.o: deque.c containers.h ccl_internal.h 79 | hashtable.o: hashtable.c containers.h ccl_internal.h 80 | dlist.o: dlist.c containers.h ccl_internal.h 81 | list.o: list.c containers.h ccl_internal.h 82 | dictionary.o: dictionary.c dictionarygen.c containers.h ccl_internal.h 83 | wdictionary.o: wdictionary.c dictionarygen.c containers.h ccl_internal.h 84 | qsortex.o: qsortex.c containers.h ccl_internal.h 85 | generic.o: generic.c containers.h ccl_internal.h 86 | heap.o: heap.c containers.h ccl_internal.h 87 | memorymanager.o: memorymanager.c containers.h ccl_internal.h 88 | sequential.o: sequential.c containers.h ccl_internal.h 89 | iMask.o: iMask.c containers.h ccl_internal.h 90 | scapegoat.o: scapegoat.c containers.h ccl_internal.h 91 | wstrcollection.o: wstrcollection.c strcollectiongen.c containers.h ccl_internal.h 92 | strcollection.o: strcollection.c strcollectiongen.c containers.h ccl_internal.h 93 | stringlist.o: stringlist.c stringlistgen.c containers.h ccl_internal.h stringlist.h stringlistgen.h 94 | wstringlist.o: wstringlist.c stringlistgen.c stringlistgen.h wstringlist.h containers.h ccl_internal.h 95 | priorityqueue.o: priorityqueue.c ccl_internal.h containers.h 96 | intlist.o: intlist.h intlist.c ccl_internal.h containers.h $(LIST_GENERIC) 97 | doublelist.o: doublelist.h doublelist.c ccl_internal.h containers.h $(LIST_GENERIC) 98 | longlonglist.o: longlonglist.h longlonglist.c ccl_internal.h containers.h $(LIST_GENERIC) 99 | intdlist.o: intdlist.h intdlist.c ccl_internal.h containers.h $(LIST_GENERIC) 100 | doubledlist.o: doubledlist.h doubledlist.c ccl_internal.h containers.h $(DLIST_GENERIC) 101 | longlongdlist.o: longlongdlist.h longlongdlist.c ccl_internal.h containers.h $(DLIST_GENERIC) 102 | 103 | # This supposes that pdflatex and makeindex are in the path 104 | # please change accordingly 105 | ccl.pdf: $(TEXFILES) $(PNGFILES) 106 | makeindex ccl.idx;pdflatex ccl.tex 107 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | BUILDING the software 2 | --------------------- 3 | 1: Documentation is in the file ccl.pdf. 4 | 2: Type "make" for building the files under Unix 5 | 3: type "make -f Makefile.lcc" for building under windows 32 bit with the lcc compiler 6 | 4: Type "make -f Makefile.lcc64" for building under windows 64 bit with the lcc64 compiler 7 | 5: Type "make -f Makefile.msvc" for building under windows with the Microsoft MSVC compiler 8 | -------------------------------------------------------------------------------- /bloom.c: -------------------------------------------------------------------------------- 1 | /* 2 | The bloom filter uses k hash functions to store k bits in a bit string that 3 | represent a stored value. It can return false positives, but if it says that 4 | an element is NOT there, it is definitely not there. 5 | 6 | The size of the bloom filter and the number of hash functions you should be 7 | using depending on your application can be calculated using the formulas on 8 | the Wikipedia page: 9 | 10 | m = -n*ln(p)/(ln(2)^2) 11 | 12 | This will tell you the number of bits m to use for your filter, given the 13 | number n of elements in your filter and the false positive probability p you 14 | want to achieve. All that for the ideal number of hash functions k which you 15 | can calculate like this: 16 | 17 | k = 0.7*m/n 18 | 19 | */ 20 | #include 21 | #include 22 | #include 23 | #include "containers.h" 24 | struct tagBloomFilter { 25 | size_t count; /* Elements stored already */ 26 | size_t MaxNbOfElements; 27 | size_t HashFunctions; 28 | size_t nbOfBits; 29 | ContainerAllocator *Allocator; 30 | unsigned char *bits; 31 | unsigned Seeds[1]; 32 | }; 33 | 34 | /*----------------------------------------------------------------------------- 35 | MurmurHash2, by Austin Appleby 36 | Note - This code makes a few assumptions about how your machine behaves - 37 | 1. We can read a 4-byte value from any address without crashing 38 | 2. sizeof(int) == 4 39 | And it has a few limitations - 40 | 1. It will not work incrementally. 41 | 2. It will not produce the same results on little-endian and big-endian 42 | machines. 43 | */ 44 | static size_t Hash(const void * key, size_t len, unsigned int seed ) 45 | { 46 | /* 'm' and 'r' are mixing constants generated offline. 47 | They're not really 'magic', they just happen to work well. 48 | */ 49 | 50 | const unsigned int m = 0x5bd1e995; 51 | const int r = 24; 52 | /* Initialize the hash to a 'random' value */ 53 | size_t h = seed ^ len; 54 | /* Mix 4 bytes at a time into the hash */ 55 | const unsigned char * data = key; 56 | while(len >= 4) { 57 | unsigned int k = *(unsigned int *)data; 58 | 59 | k *= m; 60 | k ^= k >> r; 61 | k *= m; 62 | 63 | h *= m; 64 | h ^= k; 65 | 66 | data += 4; len -= 4; 67 | } 68 | /* Handle the last few bytes of the input array */ 69 | switch(len) 70 | { 71 | case 3: h ^= data[2] << 16; 72 | case 2: h ^= data[1] << 8; 73 | case 1: h ^= data[0]; 74 | h *= m; 75 | }; 76 | /* Do a few final mixes of the hash to ensure the last few 77 | bytes are well-incorporated. */ 78 | h ^= h >> 13; h *= m; h ^= h >> 15; 79 | return h; 80 | } 81 | #define TWICE_LOG_2 1.386294361119890618834464242916353136151000268720 82 | #ifdef _MSC_VER 83 | static long round(double d) 84 | { 85 | if (d > 0) return (long)(d+0.5); 86 | return (long)(d-0.5); 87 | } 88 | #endif 89 | static BloomFilter *Create(size_t nbOfElements,double Probability) 90 | { 91 | size_t nbOfBits; 92 | size_t k; 93 | BloomFilter *result; 94 | 95 | if (Probability >= 1.0 || Probability <= 0.0) { 96 | iError.RaiseError("BloomFilter.Create",CONTAINER_ERROR_BADARG); 97 | return NULL; 98 | } 99 | nbOfBits = -round(nbOfElements*log(Probability)/TWICE_LOG_2); 100 | k = round(0.7*nbOfBits/nbOfElements); 101 | result = CurrentAllocator->malloc(sizeof(BloomFilter) + k*sizeof(int)); 102 | if (result == NULL) { 103 | goto errMem; 104 | } 105 | memset(result,0,sizeof(*result)); 106 | result->bits = CurrentAllocator->malloc(1+nbOfBits/8); 107 | if (result->bits == NULL) { 108 | CurrentAllocator->free(result); 109 | errMem: 110 | iError.RaiseError("BloomFilter.Create",CONTAINER_ERROR_NOMEMORY); 111 | return NULL; 112 | } 113 | memset(result->bits,0,1+nbOfBits/8); 114 | result->nbOfBits = nbOfBits; 115 | result->MaxNbOfElements = nbOfElements; 116 | result->HashFunctions = k; 117 | while (k > 0) { 118 | k--; 119 | result->Seeds[k] = rand(); 120 | 121 | } 122 | result->Allocator = CurrentAllocator; 123 | return result; 124 | } 125 | 126 | static size_t CalculateSpace(size_t nbOfElements,double Probability) 127 | { 128 | size_t nbOfBits; 129 | size_t k,result; 130 | 131 | if (Probability >= 1.0 || Probability <= 0.0) { 132 | iError.RaiseError("BloomFilter.CalculateSpace",CONTAINER_ERROR_BADARG); 133 | return 0; 134 | } 135 | nbOfBits = -round(nbOfElements*log(Probability)/TWICE_LOG_2); 136 | k = round(0.7*nbOfBits/nbOfElements); 137 | result = (sizeof(BloomFilter) + k*sizeof(int)); 138 | result += (1+nbOfBits/8); 139 | return result; 140 | } 141 | 142 | static size_t Add(BloomFilter *b, const void *key, size_t keylen) 143 | { 144 | size_t hash; 145 | size_t i; 146 | 147 | if (b->MaxNbOfElements <= b->count) { 148 | iError.RaiseError("BloomFilter.Add",CONTAINER_FULL); 149 | return 0; 150 | } 151 | for (i=0; iHashFunctions;i++) { 152 | hash = Hash(key,keylen,b->Seeds[i]); 153 | hash %= b->nbOfBits; 154 | b->bits[hash >> 3] |= 1 << (hash&7); 155 | } 156 | return ++b->count; 157 | } 158 | 159 | static int Find(BloomFilter *b, const void *key, size_t keylen) 160 | { 161 | size_t hash; 162 | size_t i; 163 | 164 | if (b == NULL || key== NULL || keylen == 0) { 165 | iError.RaiseError("iBloomFilter.Find",CONTAINER_ERROR_BADARG); 166 | return CONTAINER_ERROR_BADARG; 167 | } 168 | for (i=0; iHashFunctions;i++) { 169 | hash = Hash(key,keylen,b->Seeds[i]); 170 | hash %= b->nbOfBits; 171 | if ((b->bits[hash >> 3] & (1 << (hash&7))) == 0) 172 | return 0; 173 | } 174 | return 1; 175 | } 176 | 177 | static int Clear(BloomFilter *b) 178 | { 179 | if (b == NULL) { 180 | iError.RaiseError("iBloomFilter.Find",CONTAINER_ERROR_BADARG); 181 | return CONTAINER_ERROR_BADARG; 182 | } 183 | memset(b->bits,0,1+b->nbOfBits/8); 184 | return 1; 185 | } 186 | 187 | static int Finalize(BloomFilter *b) 188 | { 189 | if (b == NULL) 190 | return CONTAINER_ERROR_BADARG; 191 | b->Allocator->free(b->bits); 192 | b->Allocator->free(b); 193 | return 1; 194 | 195 | } 196 | 197 | 198 | BloomFilterInterface iBloomFilter = { 199 | CalculateSpace, 200 | Create, 201 | Add, 202 | Find, 203 | Clear, 204 | Finalize, 205 | }; 206 | -------------------------------------------------------------------------------- /buffer.c: -------------------------------------------------------------------------------- 1 | #include "containers.h" 2 | 3 | struct _StreamBuffer { 4 | size_t Size; 5 | size_t Cursor; 6 | unsigned Flags; 7 | ContainerAllocator *Allocator; 8 | char *Data; 9 | } ; 10 | 11 | #define SB_READ_FLAG 1 12 | #define SB_WRITE_FLAG 2 13 | #define SB_APPEND_FLAG 4 14 | #define SB_FIXED 8 15 | 16 | #define FCLOSE_DESTROYS 8 17 | 18 | static int Finalize(StreamBuffer *b); 19 | static StreamBuffer *CreateWithAllocator(size_t size,const ContainerAllocator *Allocator) 20 | { 21 | StreamBuffer *result; 22 | 23 | if (size == 0) 24 | size = 1024; 25 | result = Allocator->malloc(sizeof(StreamBuffer)); 26 | if (result == NULL) { 27 | iError.RaiseError("iStreamBuffer.Create",CONTAINER_ERROR_NOMEMORY); 28 | return NULL; 29 | } 30 | memset(result,0,sizeof(StreamBuffer)); 31 | result->Allocator = (ContainerAllocator *)Allocator; 32 | result->Data = Allocator->malloc(size); 33 | if (result->Data == NULL) { 34 | Allocator->free(result); 35 | return NULL; 36 | } 37 | result->Size = size; 38 | memset(result->Data,0,size); 39 | return result; 40 | } 41 | 42 | static StreamBuffer *Create(size_t size) 43 | { 44 | return CreateWithAllocator(size,CurrentAllocator); 45 | } 46 | 47 | static StreamBuffer *CreateFromFile(const char *FileName) 48 | { 49 | FILE *f = fopen(FileName,"rb"); 50 | StreamBuffer *result = NULL; 51 | size_t siz; 52 | if (f == NULL) { 53 | iError.RaiseError("iBuffer.CreateFromFile",CONTAINER_ERROR_NOENT,FileName); 54 | return NULL; 55 | } 56 | else if (fseek(f, 0, SEEK_END)) { 57 | goto err; 58 | } 59 | siz = ftell(f); 60 | if ((int)siz < 0) goto err; 61 | fseek(f,0,SEEK_SET); 62 | result = Create(siz+1); 63 | if (result == NULL) goto err; 64 | if (siz != fread(result->Data,1,siz,f)) { 65 | iError.RaiseError("iBuffer.CreateFromFile",CONTAINER_ERROR_FILE_READ); 66 | Finalize(result); 67 | result = NULL; 68 | } 69 | err: 70 | fclose(f); 71 | return result; 72 | } 73 | 74 | static int enlargeBuffer(StreamBuffer *b,size_t chunkSize) 75 | { 76 | char *p; 77 | size_t newSiz; 78 | 79 | if (chunkSize < b->Size/2) 80 | newSiz = b->Size/2; 81 | else newSiz = chunkSize; 82 | p = b->Allocator->realloc(b->Data,b->Size+newSiz); 83 | if (p == NULL) 84 | return CONTAINER_ERROR_NOMEMORY; 85 | b->Data = p; 86 | b->Size += newSiz; 87 | return 1; 88 | } 89 | 90 | static size_t Write(StreamBuffer *b,void *data, size_t siz) 91 | { 92 | if (b == NULL) { 93 | iError.RaiseError("iStreamBuffer.Write",CONTAINER_ERROR_BADARG); 94 | return 0; 95 | } 96 | if ((b->Cursor + siz) >= b->Size) { 97 | int r = enlargeBuffer(b,b->Size+siz); 98 | if (r < 0) 99 | return 0; 100 | } 101 | memcpy(b->Data+b->Cursor,data,siz); 102 | b->Cursor += siz; 103 | return siz; 104 | } 105 | 106 | static size_t Read(StreamBuffer *b, void *data, size_t siz) 107 | { 108 | size_t len; 109 | if (b == NULL || data == NULL || siz == 0) { 110 | iError.RaiseError("iStreamBuffer.Read",CONTAINER_ERROR_BADARG); 111 | return 0; 112 | } 113 | if (b->Cursor >= b->Size) 114 | return 0; 115 | len = siz; 116 | if (b->Size - b->Cursor < len) 117 | len = b->Size - b->Cursor; 118 | memcpy(data,b->Data+b->Cursor,len); 119 | b->Cursor += len; 120 | return len; 121 | } 122 | 123 | static int SetPosition(StreamBuffer *b,size_t pos) 124 | { 125 | if (b == NULL) { 126 | iError.RaiseError("iStreamBuffer.SetPosition",CONTAINER_ERROR_BADARG); 127 | return CONTAINER_ERROR_BADARG; 128 | } 129 | if (pos > b->Size) 130 | pos = b->Size; 131 | b->Cursor = pos; 132 | return 1; 133 | } 134 | 135 | static size_t GetPosition(const StreamBuffer *b) 136 | { 137 | if (b == NULL) 138 | return 0; 139 | return b->Cursor; 140 | } 141 | 142 | static size_t StreamBufferSize(const StreamBuffer *b) 143 | { 144 | if (b == NULL) 145 | return sizeof(StreamBuffer); 146 | return b->Size; 147 | } 148 | 149 | static int Clear(StreamBuffer *b) 150 | { 151 | if (b == NULL) { 152 | iError.RaiseError("iStreamBuffer.Clear",CONTAINER_ERROR_BADARG); 153 | return CONTAINER_ERROR_BADARG; 154 | } 155 | memset(b->Data,0,b->Size); 156 | b->Cursor = 0; 157 | return 1; 158 | } 159 | 160 | static int Finalize(StreamBuffer *b) 161 | { 162 | if (b == NULL) { 163 | iError.RaiseError("iStreamBuffer.Finalize",CONTAINER_ERROR_BADARG); 164 | return CONTAINER_ERROR_BADARG; 165 | } 166 | b->Allocator->free(b->Data); 167 | b->Allocator->free(b); 168 | return 1; 169 | } 170 | 171 | static char *GetData(const StreamBuffer *b) 172 | { 173 | if (b == NULL) { 174 | iError.RaiseError("iStreamBuffer.Finalize",CONTAINER_ERROR_BADARG); 175 | return NULL; 176 | } 177 | return b->Data; 178 | } 179 | 180 | static int Resize(StreamBuffer *b,size_t newSize) 181 | { 182 | char *tmp; 183 | 184 | if (b == NULL) { 185 | iError.RaiseError("iStreamBuffer.Resize",CONTAINER_ERROR_BADARG); 186 | return CONTAINER_ERROR_BADARG; 187 | } 188 | if (newSize == b->Size) 189 | return 0; 190 | tmp = b->Allocator->realloc(b->Data,newSize); 191 | if (tmp == NULL) { 192 | iError.RaiseError("iStreamBuffer.Resize",CONTAINER_ERROR_NOMEMORY); 193 | return CONTAINER_ERROR_NOMEMORY; 194 | } 195 | b->Data = tmp; 196 | b->Size = newSize; 197 | return 1; 198 | } 199 | 200 | static int ReadFromFile(StreamBuffer *b,FILE *infile) 201 | { 202 | if (b == NULL) { 203 | iError.RaiseError("iStreamBuffer.ReadFromFile",CONTAINER_ERROR_BADARG); 204 | return CONTAINER_ERROR_BADARG; 205 | } 206 | b->Cursor = 0; 207 | return fread(b->Data,1,b->Size,infile); 208 | } 209 | 210 | static int WriteToFile(StreamBuffer *b,FILE *outfile) 211 | { 212 | if (b == NULL) { 213 | iError.RaiseError("iStreamBuffer.WriteToFile",CONTAINER_ERROR_BADARG); 214 | return CONTAINER_ERROR_BADARG; 215 | } 216 | b->Cursor = 0; 217 | return fwrite(b->Data,1,b->Size,outfile); 218 | } 219 | 220 | StreamBufferInterface iStreamBuffer = { 221 | Create, 222 | CreateWithAllocator, 223 | CreateFromFile, 224 | Read, 225 | Write, 226 | SetPosition, 227 | GetPosition, 228 | GetData, 229 | StreamBufferSize, 230 | Clear, 231 | Finalize, 232 | Resize, 233 | ReadFromFile, 234 | WriteToFile, 235 | }; 236 | /* -------------------------------------------------------------------------- 237 | Circular buffers 238 | ------------------------------------------------------------------------- */ 239 | struct _CircularBuffer { 240 | size_t maxCount; 241 | size_t ElementSize; 242 | size_t head; 243 | size_t tail; 244 | ContainerAllocator *Allocator; 245 | DestructorFunction DestructorFn; 246 | unsigned char *data; 247 | }; 248 | 249 | 250 | static DestructorFunction SetDestructor(CircularBuffer *cb,DestructorFunction fn) 251 | { 252 | DestructorFunction oldfn; 253 | if (cb == NULL) 254 | return NULL; 255 | oldfn = cb->DestructorFn; 256 | if (fn) 257 | cb->DestructorFn = fn; 258 | return oldfn; 259 | } 260 | 261 | static size_t Size(const CircularBuffer *cb) 262 | { 263 | if (cb == NULL) 264 | return sizeof(CircularBuffer); 265 | return cb->head - cb->tail; 266 | } 267 | 268 | static int Add( CircularBuffer * b,const void *data_element) 269 | { 270 | unsigned char *ring_data = NULL; 271 | int result = 1; 272 | 273 | if (b == NULL || data_element == NULL) { 274 | iError.RaiseError("iCircularBuffer.Add",CONTAINER_ERROR_BADARG); 275 | return CONTAINER_ERROR_BADARG; 276 | } 277 | if (b->maxCount == (b->head - b->tail)) { 278 | b->head = 0; 279 | result = 0; 280 | } 281 | ring_data = b->data + ((b->head % b->maxCount) * b->ElementSize); 282 | memcpy(ring_data,data_element,b->ElementSize); 283 | b->head++; 284 | return result; 285 | } 286 | 287 | static int PopFront(CircularBuffer *b,void *result) 288 | { 289 | void *data; 290 | 291 | if (b == NULL) { 292 | iError.RaiseError("iCircularBuffer.PopFront",CONTAINER_ERROR_BADARG); 293 | return CONTAINER_ERROR_BADARG; 294 | } 295 | if (b->head == b->tail) 296 | return 0; 297 | data = &(b->data[(b->tail % b->maxCount) * b->ElementSize]); 298 | b->tail++; 299 | if (result) 300 | memcpy(result,data,b->ElementSize); 301 | return 1; 302 | } 303 | 304 | static int PeekFront(CircularBuffer *b,void *result) 305 | { 306 | void *data; 307 | 308 | if (b == NULL || result == NULL) { 309 | iError.RaiseError("iCircularBuffer.PeekFront",CONTAINER_ERROR_BADARG); 310 | return CONTAINER_ERROR_BADARG; 311 | } 312 | if (b->head == b->tail) 313 | return 0; 314 | data = &(b->data[(b->tail % b->maxCount) * b->ElementSize]); 315 | memcpy(result,data,b->ElementSize); 316 | return 1; 317 | } 318 | 319 | static CircularBuffer *CreateCBWithAllocator(size_t sizElement,size_t sizeBuffer,const ContainerAllocator *allocator) 320 | { 321 | CircularBuffer *result; 322 | 323 | if (sizElement == 0 || sizeBuffer == 0 || allocator == NULL) { 324 | iError.RaiseError("iCircularBuffer.Create",CONTAINER_ERROR_BADARG); 325 | return NULL; 326 | } 327 | result = allocator->malloc(sizeof(CircularBuffer)); 328 | if (result == NULL) { 329 | iError.RaiseError("iCircularBuffer.Create",CONTAINER_ERROR_NOMEMORY); 330 | return NULL; 331 | } 332 | memset(result,0,sizeof(CircularBuffer)); 333 | result->maxCount = sizeBuffer; 334 | result->ElementSize = sizElement; 335 | result->Allocator = (ContainerAllocator *)allocator; 336 | sizElement = sizElement*sizeBuffer; /* Here we should test for overflow */ 337 | result->data = allocator->malloc(sizElement); 338 | if (result->data == NULL) { 339 | allocator->free(result); 340 | iError.RaiseError("iCircularBuffer.Create",CONTAINER_ERROR_NOMEMORY); 341 | return NULL; 342 | } 343 | return result; 344 | } 345 | 346 | static CircularBuffer *CreateCB(size_t sizElement,size_t sizeBuffer) 347 | { 348 | return CreateCBWithAllocator(sizElement, sizeBuffer, CurrentAllocator); 349 | } 350 | 351 | static int CBClear(CircularBuffer *cb) 352 | { 353 | unsigned char *p; 354 | size_t i; 355 | if (cb == NULL) { 356 | iError.RaiseError("iCircularBuffer.Clear",CONTAINER_ERROR_BADARG); 357 | return CONTAINER_ERROR_BADARG; 358 | } 359 | if (cb->head == cb->tail) 360 | return 0; 361 | p = cb->data; 362 | if (cb->DestructorFn) { 363 | for (i=cb->tail; ihead;i++) { 364 | cb->DestructorFn(p); 365 | p += cb->ElementSize; 366 | } 367 | } 368 | memset(p,0,cb->ElementSize*(cb->head-cb->tail)); 369 | cb->head = cb->tail = 0; 370 | return 1; 371 | } 372 | 373 | static int CBFinalize(CircularBuffer *cb) 374 | { 375 | if (cb == NULL) { 376 | iError.RaiseError("iCircularBuffer.Finalize",CONTAINER_ERROR_BADARG); 377 | return CONTAINER_ERROR_BADARG; 378 | } 379 | CBClear(cb); 380 | cb->Allocator->free(cb->data); 381 | cb->Allocator->free(cb); 382 | return 1; 383 | } 384 | 385 | static size_t Sizeof(const CircularBuffer *cb) 386 | { 387 | size_t result = sizeof(CircularBuffer); 388 | if (cb == NULL) 389 | return result; 390 | result += (cb->head - cb->tail)*cb->ElementSize; 391 | return result; 392 | } 393 | 394 | CircularBufferInterface iCircularBuffer = { 395 | Size, 396 | Add, 397 | PopFront, 398 | PeekFront, 399 | CreateCBWithAllocator, 400 | CreateCB, 401 | CBClear, 402 | CBFinalize, 403 | Sizeof, 404 | SetDestructor, 405 | }; 406 | -------------------------------------------------------------------------------- /ccldoc/AbstractIterator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lupus/ccl/5302c7ecd23edbeea3d523e263aa303a71089c7a/ccldoc/AbstractIterator.png -------------------------------------------------------------------------------- /ccldoc/AuxiliaryInterfaces.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lupus/ccl/5302c7ecd23edbeea3d523e263aa303a71089c7a/ccldoc/AuxiliaryInterfaces.png -------------------------------------------------------------------------------- /ccldoc/Basic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lupus/ccl/5302c7ecd23edbeea3d523e263aa303a71089c7a/ccldoc/Basic.png -------------------------------------------------------------------------------- /ccldoc/BloomFilter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lupus/ccl/5302c7ecd23edbeea3d523e263aa303a71089c7a/ccldoc/BloomFilter.png -------------------------------------------------------------------------------- /ccldoc/Circular.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lupus/ccl/5302c7ecd23edbeea3d523e263aa303a71089c7a/ccldoc/Circular.png -------------------------------------------------------------------------------- /ccldoc/Containers.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lupus/ccl/5302c7ecd23edbeea3d523e263aa303a71089c7a/ccldoc/Containers.png -------------------------------------------------------------------------------- /ccldoc/DListVocabulary.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lupus/ccl/5302c7ecd23edbeea3d523e263aa303a71089c7a/ccldoc/DListVocabulary.png -------------------------------------------------------------------------------- /ccldoc/Dictionary.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lupus/ccl/5302c7ecd23edbeea3d523e263aa303a71089c7a/ccldoc/Dictionary.png -------------------------------------------------------------------------------- /ccldoc/Feux.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lupus/ccl/5302c7ecd23edbeea3d523e263aa303a71089c7a/ccldoc/Feux.png -------------------------------------------------------------------------------- /ccldoc/HashTable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lupus/ccl/5302c7ecd23edbeea3d523e263aa303a71089c7a/ccldoc/HashTable.png -------------------------------------------------------------------------------- /ccldoc/Iterator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lupus/ccl/5302c7ecd23edbeea3d523e263aa303a71089c7a/ccldoc/Iterator.png -------------------------------------------------------------------------------- /ccldoc/ListContainerSourceFiles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lupus/ccl/5302c7ecd23edbeea3d523e263aa303a71089c7a/ccldoc/ListContainerSourceFiles.png -------------------------------------------------------------------------------- /ccldoc/ListContainerSpecializations.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lupus/ccl/5302c7ecd23edbeea3d523e263aa303a71089c7a/ccldoc/ListContainerSpecializations.png -------------------------------------------------------------------------------- /ccldoc/ListVocabulary.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lupus/ccl/5302c7ecd23edbeea3d523e263aa303a71089c7a/ccldoc/ListVocabulary.png -------------------------------------------------------------------------------- /ccldoc/Makefile: -------------------------------------------------------------------------------- 1 | MAKEINDEX=makeindex 2 | PDFLATEX=pdflatex 3 | PNGS=AuxiliaryInterfaces.png DListVocabulary.png Pool.png bitstrings.png Basic.png Dictionary.png StreamBuffer.png list.png BloomFilter.png Iterator.png ValArray.png Circular.png ListVocabulary.png VectorVocabulary.png Containers.png Memorymanagement.png Vocabulary.png 4 | 5 | all: ccl.pdf ccl.html 6 | 7 | ccl.pdf: ccl.tex table.tex $(PNGS) ../containers.h 8 | $(PDFLATEX) ccl.tex;$(MAKEINDEX) ccl.idx;$(PDFLATEX) ccl.tex 9 | 10 | table.tex: dotable ../containers.h ../valarraygen.h 11 | ./dotable 12 | 13 | ccl.html: tth ccl.tex $(PNGS) table.tex 14 | ./tth ccl.tex 15 | 16 | dotable: dotable.c 17 | gcc -g -o dotable -I.. dotable.c ../libccl.a 18 | 19 | tth: tth.c 20 | gcc -o tth -g tth.c 21 | clean: 22 | rm -f table.tex ccl.pdf ccl.html dotable tth ccldoc.zip ccl.tid ccl.idx ccl.log ccl.toc \ 23 | ccl.tin ccl.aux ccl.tms ccl.ilg StreamBuffer.tex \ 24 | BitString.tex Dictionary.tex Queue.tex ValArray.tex strcollection.tex \ 25 | ContainerHeap.tex Dlist.tex List.tex Deque.tex HashTable.tex PQueue.tex TreeMap.tex WDictionary.tex 26 | 27 | zip: 28 | zip -9 ccldoc.zip dotable.c ccl.tex tth.c $(PNGS) Introduction.tex Makefile rgb.tex 29 | -------------------------------------------------------------------------------- /ccldoc/Memorymanagement.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lupus/ccl/5302c7ecd23edbeea3d523e263aa303a71089c7a/ccldoc/Memorymanagement.png -------------------------------------------------------------------------------- /ccldoc/NamingConventions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lupus/ccl/5302c7ecd23edbeea3d523e263aa303a71089c7a/ccldoc/NamingConventions.png -------------------------------------------------------------------------------- /ccldoc/Pool.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lupus/ccl/5302c7ecd23edbeea3d523e263aa303a71089c7a/ccldoc/Pool.png -------------------------------------------------------------------------------- /ccldoc/Returncodes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lupus/ccl/5302c7ecd23edbeea3d523e263aa303a71089c7a/ccldoc/Returncodes.png -------------------------------------------------------------------------------- /ccldoc/SingleLinkedList.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lupus/ccl/5302c7ecd23edbeea3d523e263aa303a71089c7a/ccldoc/SingleLinkedList.png -------------------------------------------------------------------------------- /ccldoc/StreamBuffer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lupus/ccl/5302c7ecd23edbeea3d523e263aa303a71089c7a/ccldoc/StreamBuffer.png -------------------------------------------------------------------------------- /ccldoc/ValArray.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lupus/ccl/5302c7ecd23edbeea3d523e263aa303a71089c7a/ccldoc/ValArray.png -------------------------------------------------------------------------------- /ccldoc/Vector.tex: -------------------------------------------------------------------------------- 1 | \begin{verbatim} 2 | typedef struct tagVectorInterface { 3 | int (*Add)(Vector *AL,const void *newval); 4 | int (*AddRange)(Vector *AL,size_t n,const void *newvalues); 5 | int (*Append)(Vector *AL1, Vector *AL2); 6 | int (*Apply)(Vector *AL,int (*Applyfn)(void *element,void * arg), 7 | void *arg); 8 | void *(*Back)(const Vector *AL); 9 | int (*Clear)(Vector *AL); 10 | Mask *(*CompareEqual)(const Vector *left,const Vector *right, 11 | Mask *m); 12 | Mask *(*CompareEqualScalar)(const Vector *left, const void *right, 13 | Mask *m); 14 | int (*Contains)(const Vector *AL,const void *element, 15 | void *ExtraArgs); 16 | Vector *(*Copy)(const Vector *AL); 17 | int (*CopyElement)(const Vector *AL,size_t idx,void *outbuf); 18 | void **(*CopyTo)(const Vector *AL); 19 | Vector *(*Create)(size_t elementsize,size_t startsize); 20 | Vector *(*CreateWithAllocator)(size_t elemsiz,size_t startsiz, 21 | const ContainerAllocator *mm); 22 | int (*Equal)(const Vector *first,const Vector *second); 23 | int (*Erase)(Vector *AL,const void *); 24 | int (*EraseAll)(Vector *AL,const void *); 25 | int (*EraseAt)(Vector *AL,size_t idx); 26 | int (*Finalize)(Vector *AL); 27 | void *(*Front)(const Vector *AL); 28 | const ContainerAllocator *(*GetAllocator)(const Vector *AL); 29 | size_t (*GetCapacity)(const Vector *AL); 30 | void **(*GetData)(const Vector *AL); 31 | void *(*GetElement)(const Vector *AL,size_t idx); 32 | size_t (*GetElementSize)(const Vector *AL); 33 | unsigned (*GetFlags)(const Vector *AL); 34 | Vector *(*GetRange)(const Vector *AL, size_t start, size_t end); 35 | Vector *(*IndexIn)(Vector *SC,Vector *AL); 36 | int (*IndexOf)(const Vector *AL,const void *data,void *ExtraArgs, 37 | size_t *result); 38 | Vector *(*Init)(Vector *r,size_t elementsize,size_t startsize); 39 | int (*InitIterator)(Vector *V,void *buf); 40 | Vector *(*InitializeWith)(size_t elementSize, size_t n, 41 | const void *Data); 42 | int (*Insert)(Vector *AL,void *); 43 | int (*InsertAt)(Vector *AL,size_t idx,void *newval); 44 | int (*InsertIn)(Vector *AL, size_t idx,Vector *newData); 45 | Vector *(*Load)(FILE *stream, ReadFunction readFn,void *arg); 46 | int (*Mismatch)(Vector *a1,Vector *a2,size_t *mismatch); 47 | Iterator *(*NewIterator)(Vector *AL); 48 | int (*PopBack)(Vector *AL,void *result); 49 | int (*PushBack)(Vector *AL,const void *str); 50 | int (*RemoveRange)(Vector *SC,size_t start,size_t end); 51 | int (*ReplaceAt)(Vector *AL,size_t idx,void *newval); 52 | int (*Reserve)(Vector *src,size_t newCapacity); 53 | int (*Resize)(Vector *AL,size_t newSize); 54 | int (*Reverse)(Vector *AL); 55 | int (*RotateLeft)(Vector *V,size_t n); 56 | int (*RotateRight)(Vector *V,size_t n); 57 | int (*Save)(const Vector *AL,FILE *stream, SaveFunction saveFn, 58 | void *arg); 59 | int (*SearchWithKey)(Vector *vec,size_t startByte,size_t sizeKey, 60 | size_t startIndex,void *item,size_t *result); 61 | int (*Select)(Vector *src,const Mask *m); 62 | Vector *(*SelectCopy)(Vector *src,Mask *m); 63 | int (*SetCapacity)(Vector *AL,size_t newCapacity); 64 | CompareFunction (*SetCompareFunction)(Vector *l, 65 | CompareFunction fn); 66 | DestructorFunction (*SetDestructor)(Vector *v, 67 | DestructorFunction fn); 68 | ErrorFunction (*SetErrorFunction)(Vector *AL,ErrorFunction); 69 | unsigned (*SetFlags)(Vector *AL,unsigned flags); 70 | size_t (*Size)(const Vector *AL); 71 | size_t (*Sizeof)(const Vector *AL); 72 | size_t (*SizeofIterator)(const Vector *); 73 | int (*Sort)(Vector *AL); 74 | int (*deleteIterator)(Iterator *); 75 | } VectorInterface; 76 | \end{verbatim} 77 | -------------------------------------------------------------------------------- /ccldoc/VectorVocabulary.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lupus/ccl/5302c7ecd23edbeea3d523e263aa303a71089c7a/ccldoc/VectorVocabulary.png -------------------------------------------------------------------------------- /ccldoc/Vocabulary.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lupus/ccl/5302c7ecd23edbeea3d523e263aa303a71089c7a/ccldoc/Vocabulary.png -------------------------------------------------------------------------------- /ccldoc/bitstrings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lupus/ccl/5302c7ecd23edbeea3d523e263aa303a71089c7a/ccldoc/bitstrings.png -------------------------------------------------------------------------------- /ccldoc/dotable.c: -------------------------------------------------------------------------------- 1 | #include "containers.h" 2 | static char *ContainerNames[] ={ 3 | "List", 4 | "Dlist", 5 | // "EXTERNAL_NAME", 6 | "Vector", 7 | "ValArray", 8 | "BitString", 9 | "strCollection", 10 | "Queue", 11 | "Deque", 12 | "Dictionary", 13 | "HashTable", 14 | "TreeMap", 15 | "PQueue", 16 | "StreamBuffer", 17 | NULL 18 | }; 19 | 20 | static char *ExceptionsTable[] = { 21 | "Create", 22 | "CreateWithAllocator", 23 | "CreateFromFile", 24 | "CreateSequence", 25 | "InitializeWith", 26 | "Init", 27 | "InitWithAllocator", 28 | "Load", 29 | "StringToBitString", 30 | "ObjectToBitString", 31 | }; 32 | 33 | #define NbContainers (sizeof(ContainerNames)/sizeof(ContainerNames[0])-1) 34 | 35 | typedef struct Data { 36 | unsigned char *ApiName; 37 | int type[NbContainers]; 38 | } DataPoint; 39 | 40 | int Strtrim(char *str) 41 | { 42 | char *src = str,*dst = str,*start = str; 43 | 44 | while (isspace(*src)) 45 | src++; 46 | do { 47 | while (*src && !isspace(*src)) 48 | *dst++ = *src++; 49 | if (*src) { 50 | *dst++ = *src++; 51 | while (isspace(*src) && *src != '\n' && *src != '\r') 52 | src++; 53 | } 54 | } while (*src); 55 | if (dst != start && isspace(dst[-1]) && dst[-1] != '\n') 56 | dst--; 57 | *dst = 0; 58 | return dst - src; 59 | } 60 | 61 | 62 | static Dictionary *Data; 63 | static strCollection *Exceptions; 64 | static strCollection *ContainerTable; 65 | 66 | static int FindType(char *type) 67 | { 68 | size_t typ=0; 69 | int r = istrCollection.IndexOf(ContainerTable,type,&typ); 70 | if (r < 0) 71 | return r; 72 | return typ; 73 | } 74 | 75 | static int isId(char *p) 76 | { 77 | if (*p >= 'a' && *p <= 'z') 78 | return 1; 79 | if (*p >= 'A' && *p <= 'Z') 80 | return 1; 81 | if (*p >= '0' && *p <='9') 82 | return 1; 83 | if (*p == '_') 84 | return 1; 85 | return 0; 86 | } 87 | 88 | static char *GetId(char *start) 89 | { 90 | while (isId(start)) 91 | start++; 92 | return start; 93 | } 94 | 95 | static int ScanOneLine(unsigned char *line) 96 | { 97 | char *q,*p = strchr(line,')'); 98 | DataPoint d; 99 | const DataPoint *old=NULL; 100 | size_t typ=0; 101 | int t; 102 | if (p == NULL) 103 | return -1; 104 | q = p+1; 105 | *p-- = 0; 106 | while (*p == ' ' ) 107 | p--; 108 | while (isId(p)) { 109 | p--; 110 | } 111 | p++; 112 | while (*q == ' ') q++; 113 | if (*q == '(') 114 | q++; 115 | else return -1; 116 | 117 | 118 | if (Data == NULL) { 119 | Data = iDictionary.Create(sizeof(DataPoint),200); 120 | } 121 | old = iDictionary.GetElement(Data,p); 122 | 123 | memset(&d,0,sizeof(d)); 124 | t = istrCollection.IndexOf(Exceptions,p,&typ); 125 | //printf("%s: t=%d, index %ull\n",p,t,typ); 126 | if (t >= 0) { 127 | char *save = p; 128 | p = line; 129 | 130 | while (*p == ' ' || *p == '\t') 131 | p++; 132 | q = GetId(p); 133 | *q = 0; 134 | t = FindType(p); 135 | if (t < 0) { 136 | if (strcmp(p,"ElementType")) { 137 | return -1; 138 | } 139 | typ = 3; 140 | } 141 | else typ = t; 142 | if (old == NULL) d.ApiName = strdup(save); 143 | } 144 | else { 145 | if (old ==NULL) d.ApiName = strdup(p); 146 | p = q; 147 | q = GetId(q); 148 | *q=0; 149 | if (!strcmp(p,"const")) { 150 | q++; 151 | while (*q == ' ' || *q == '\t') 152 | q++; 153 | p = q; 154 | q = GetId(q); 155 | *q=0; 156 | } 157 | t = FindType(p); 158 | if (t < 0) { 159 | if (strcmp(p,"ElementType")) { 160 | free(d.ApiName); 161 | return -1; 162 | } 163 | typ = 12; 164 | } 165 | else typ = t; 166 | } 167 | if (old) { 168 | memcpy(&d,old,sizeof(DataPoint)); 169 | } 170 | d.type[typ] = typ+1; 171 | if (Data == NULL) { 172 | Data = iDictionary.Create(sizeof(DataPoint),200); 173 | } 174 | 175 | iDictionary.Add(Data,d.ApiName,&d); 176 | return 1; 177 | } 178 | 179 | static int comp(const void **s1,const void **s2, CompareInfo *info) 180 | { 181 | const char *p = strstr(*s1,"(*"); 182 | const char *q = strstr(*s2,"(*"); 183 | if (p == NULL || q == NULL) { 184 | fprintf(stderr,"BUG***\n"); 185 | exit(-1); 186 | } 187 | return strcmp(p,q); 188 | } 189 | 190 | static void EliminateComments(strCollection *sc) 191 | { 192 | Iterator *it = istrCollection.NewIterator(sc); 193 | char *p; 194 | 195 | for (p = it->GetFirst(it); p; p = it->GetNext(it)) { 196 | char *q = strstr(p,"/*"); 197 | if (q) *q = 0; 198 | } 199 | } 200 | 201 | static int trim(strCollection *sc,int idx,char *p) 202 | { 203 | char *q = strrchr(p,','); 204 | char *s = strchr(p,'('); 205 | char buf[1024]; 206 | int i,len1,save; 207 | 208 | if (q == NULL) return 1; 209 | if (s == NULL) s = p; 210 | while (q-p > 70) { 211 | char *tmp; 212 | *q=0; 213 | tmp = strrchr(p,','); 214 | *q=','; 215 | if (tmp != NULL) 216 | q=tmp; 217 | else break; 218 | } 219 | len1 = s-p; 220 | if (len1+strlen(q) > 75) { 221 | len1 = 75-strlen(q); 222 | } 223 | if (len1 < 8) len1 = 8; 224 | for (i=0; i 75) { 232 | return 1+trim(sc,idx+1,istrCollection.GetElement(sc,idx+1)); 233 | } 234 | return 2; 235 | } 236 | 237 | 238 | static void doFile(char *name,Iterator *it) 239 | { 240 | FILE *f; 241 | const char *p; 242 | char *q,buf[4096]; 243 | int counter = 0; 244 | Iterator *It; 245 | strCollection *sc = istrCollection.CreateWithAllocator(50,&iDebugMalloc); 246 | do { 247 | p = it->GetNext(it); 248 | q = strstr(p,"//"); 249 | if (q) *q=0; 250 | q = strstr(p,"(*"); 251 | if (q) { 252 | Strtrim(p); 253 | sprintf(buf," %s",p); 254 | istrCollection.Add(sc,buf); 255 | } 256 | } while (strchr(p,'}') == 0); 257 | istrCollection.SetCompareFunction(sc,comp); 258 | EliminateComments(sc); 259 | istrCollection.Sort(sc); 260 | istrCollection.InsertAt(sc,0,"\\begin{verbatim}"); 261 | sprintf(buf,"typedef struct tag%sInterface {",name); 262 | istrCollection.InsertAt(sc,1,buf); 263 | sprintf(buf,"} %sInterface;",name); 264 | istrCollection.Add(sc,buf); 265 | istrCollection.Add(sc,"\\end{verbatim}"); 266 | while (counter < istrCollection.Size(sc)) { 267 | p = istrCollection.GetElement(sc,counter); 268 | if (strlen(p) > 70) counter += trim(sc,counter,p); 269 | else counter++; 270 | } 271 | strcat(name,".tex"); 272 | istrCollection.WriteToFile(sc,name); 273 | } 274 | 275 | 276 | static void ExtractIds(char *fname) 277 | { 278 | strCollection *text = istrCollection.CreateFromFile(fname); 279 | Iterator *it = istrCollection.NewIterator(text); 280 | char *p; 281 | for (p = it->GetFirst(it); p != NULL; p = it->GetNext(it)) { 282 | char buf[512]; 283 | if (strstr(p,"typedef") && strstr(p,"struct") && 284 | strchr(p,'{')) { 285 | char *q = strstr(p,"struct"); 286 | char *name; 287 | q += 6; 288 | while (*q == ' ' || *q == '\t') 289 | q++; 290 | if (*q == 't' && q[1] == 'a' && q[2] == 'g') 291 | q += 3; 292 | if (*q == '{') { 293 | strcpy(buf,"ValArray"); 294 | doFile(buf,it); 295 | } 296 | else { 297 | int i = 0; 298 | while (*q != ' ' && *q != '{' && *q) 299 | buf[i++] = *q++; 300 | buf[i]=0; 301 | q = strstr(buf,"Interface"); 302 | if (q) *q=0; 303 | if (FindType(buf) >= 0) { 304 | doFile(buf,it); 305 | } 306 | else if (strstr(buf,"WDictionary")) { 307 | strcpy(buf,"WDictionary"); 308 | doFile(buf,it); 309 | } 310 | else if (strstr(buf,"HeapAllocator")) { 311 | strcpy(buf,"ContainerHeap"); 312 | doFile(buf,it); 313 | } 314 | } 315 | } 316 | } 317 | for (p = it->GetFirst(it); p != NULL; p = it->GetNext(it)) { 318 | int r = ScanOneLine(p); 319 | } 320 | 321 | istrCollection.deleteIterator(it); 322 | istrCollection.Finalize(text); 323 | } 324 | 325 | static int destroyDataPoint(void *pdata) 326 | { 327 | DataPoint *data = pdata; 328 | free(data->ApiName); 329 | return 1; 330 | } 331 | 332 | int main(void) 333 | { 334 | Iterator *it; 335 | DataPoint *d; 336 | strCollection *Output = istrCollection.CreateWithAllocator(100,&iDebugMalloc); 337 | int j,APITotals=0; 338 | int totals[1+NbContainers]; 339 | char buf[4096]; 340 | 341 | memset(totals,0,sizeof(totals)); 342 | Exceptions = istrCollection.InitializeWith(sizeof(ExceptionsTable)/sizeof(ExceptionsTable[0]),ExceptionsTable); 343 | ContainerTable = istrCollection.InitializeWith(NbContainers,ContainerNames); 344 | ExtractIds("../containers.h"); 345 | ExtractIds("../valarraygen.h"); 346 | ExtractIds("../stringlistgen.h"); 347 | it = iDictionary.NewIterator(Data); 348 | iDictionary.SetDestructor(Data,destroyDataPoint); 349 | for (d = it->GetFirst(it); d != NULL; d = it->GetNext(it)) { 350 | int len = strlen(d->ApiName); 351 | if (len > 15) 352 | sprintf(buf,"%-20s\t&",d->ApiName); 353 | else if (len > 12) 354 | sprintf(buf,"%-20s\t&",d->ApiName); 355 | else 356 | sprintf(buf,"%-20s\t&",d->ApiName); 357 | for (j=0; jtype[j]) { 359 | sprintf(buf+strlen(buf)," \\X "); 360 | totals[j] += 1; 361 | } 362 | else sprintf(buf+strlen(buf)," "); 363 | if (j != NbContainers-1) 364 | strcat(buf,"&"); 365 | } 366 | strcat(buf,"\\\\\n"); 367 | istrCollection.Add(Output,buf); 368 | } 369 | istrCollection.Sort(Output); 370 | istrCollection.Add(Output,"\\hline\n"); 371 | sprintf(buf,"%-20s\t&","Totals"); 372 | for (j=0; j Wed, 04 Sep 2013 13:58:16 +0400 9 | -------------------------------------------------------------------------------- /debian/compat: -------------------------------------------------------------------------------- 1 | 7 2 | -------------------------------------------------------------------------------- /debian/control: -------------------------------------------------------------------------------- 1 | Source: ccl 2 | Priority: extra 3 | Maintainer: Konstantin Olkhovskiy 4 | Build-Depends: debhelper (>= 7), cmake, libc6-dev 5 | Standards-Version: 3.8.3 6 | Section: devel 7 | 8 | Package: libccl-dev 9 | Section: libdevel 10 | Architecture: any 11 | Depends: libccl1 (= ${binary:Version}) 12 | Description: Development counterpart for libccl 13 | 14 | Package: libccl1 15 | Section: libs 16 | Architecture: any 17 | Depends: ${shlibs:Depends}, ${misc:Depends} 18 | Description: C containers library 19 | -------------------------------------------------------------------------------- /debian/libccl-dev.dirs: -------------------------------------------------------------------------------- 1 | usr/lib 2 | usr/include 3 | -------------------------------------------------------------------------------- /debian/libccl-dev.install: -------------------------------------------------------------------------------- 1 | usr/include/* 2 | #usr/lib/*.la 3 | #usr/bin/* 4 | -------------------------------------------------------------------------------- /debian/libccl1.dirs: -------------------------------------------------------------------------------- 1 | usr/lib 2 | -------------------------------------------------------------------------------- /debian/libccl1.install: -------------------------------------------------------------------------------- 1 | usr/lib/lib*.so.* 2 | usr/lib/lib*.so 3 | -------------------------------------------------------------------------------- /debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | # -*- makefile -*- 3 | # Sample debian/rules that uses debhelper. 4 | # This file was originally written by Joey Hess and Craig Small. 5 | # As a special exception, when this file is copied by dh-make into a 6 | # dh-make output file, you may use that output file without restriction. 7 | # This special exception was added by Craig Small in version 0.37 of dh-make. 8 | 9 | # Uncomment this to turn on verbose mode. 10 | #export DH_VERBOSE=1 11 | 12 | %: 13 | dh $@ 14 | -------------------------------------------------------------------------------- /dictionary.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "containers.h" 4 | #include "ccl_internal.h" 5 | #include "assert.h" 6 | 7 | #undef ITERATOR 8 | #undef CHARTYPE 9 | #undef INTERFACE 10 | #undef DATA_TYPE 11 | 12 | #define HASHFUNCTION HashFunction 13 | #define ITERATOR DictionaryIterator 14 | #define DATALIST DataList 15 | #define DATA_TYPE Dictionary 16 | #define CHARTYPE char 17 | #define INTERFACE DictionaryInterface 18 | #define EXTERNAL_NAME iDictionary 19 | #define STRCPY strcpy 20 | #define STRCMP strcmp 21 | #define STRLEN strlen 22 | #define iSTRCOLLECTION istrCollection 23 | #define STRCOLLECTION strCollection 24 | 25 | #include "dictionarygen.c" 26 | -------------------------------------------------------------------------------- /dlistgen.h: -------------------------------------------------------------------------------- 1 | #ifndef __dlistgen_h__ 2 | #define __dlistgen_h__ 3 | #ifndef DATA_TYPE 4 | #error "The symbol DATA_TYPE MUST be defined" 5 | #else 6 | #ifndef DEFAULT_START_SIZE 7 | #define DEFAULT_START_SIZE 20 8 | #endif 9 | #ifndef INT_MAX 10 | #define INT_MAX (((unsigned)-1) >> 1) 11 | #endif 12 | #undef LIST_TYPE 13 | #undef LIST_TYPE_ 14 | #undef INTERFACE 15 | #undef ITERATOR 16 | #undef ITERFACE_NAME 17 | #undef LIST_ELEMENT 18 | #undef LIST_ELEMENT_ 19 | #undef LIST_STRUCT_INTERNAL_NAME 20 | #undef INTERFACE_STRUCT_INTERNAL_NAME 21 | 22 | #define CONCAT(x,y) x ## y 23 | #define CONCAT3_(a,b,c) a##b##c 24 | #define CONCAT3(a,b,c) CONCAT3_(a,b,c) 25 | #define EVAL(t) t 26 | #define LIST_ELEMENT_(t) CONCAT(t,DlistElement) 27 | #define LIST_ELEMENT LIST_ELEMENT_(DATA_TYPE) 28 | #define INTERFACE(t) CONCAT(t,DlistInterface) 29 | #define ITERATOR(t) CONCAT(t,DlistIterator) 30 | #define ERROR_RETURN 0 31 | 32 | #define LIST_TYPE_(t) CONCAT(t,Dlist) 33 | #define LIST_TYPE LIST_TYPE_(DATA_TYPE) 34 | #define INTERFACE_NAME(a) CONCAT3(i,EVAL(a),Dlist) 35 | #define LIST_STRUCT_INTERNAL_NAME(a) CONCAT3(__,EVAL(a),Dlist) 36 | #define INTERFACE_STRUCT_INTERNAL_NAME(a) CONCAT3(__,EVAL(a),DlistInterface) 37 | 38 | typedef struct LIST_ELEMENT { 39 | struct LIST_ELEMENT *Next; 40 | struct LIST_ELEMENT *Previous; 41 | DATA_TYPE Data; 42 | } LIST_ELEMENT; 43 | 44 | typedef struct LIST_STRUCT_INTERNAL_NAME(DATA_TYPE) LIST_TYPE; 45 | typedef struct INTERFACE_STRUCT_INTERNAL_NAME(DATA_TYPE) INTERFACE(DATA_TYPE); 46 | struct LIST_STRUCT_INTERNAL_NAME(DATA_TYPE) { 47 | INTERFACE(DATA_TYPE) *VTable; /* Methods table */ 48 | size_t count; /* in elements units */ 49 | unsigned Flags; 50 | unsigned timestamp; /* Changed at each modification */ 51 | size_t ElementSize; /* Size (in bytes) of each element */ 52 | LIST_ELEMENT *Last; /* The last item */ 53 | LIST_ELEMENT *First; /* The contents of the list start here */ 54 | CompareFunction Compare; /* Element comparison function */ 55 | ErrorFunction RaiseError; /* Error function */ 56 | ContainerHeap *Heap; 57 | const ContainerAllocator *Allocator; 58 | DestructorFunction DestructorFn; 59 | }; 60 | 61 | struct ITERATOR(DATA_TYPE) { 62 | Iterator it; 63 | LIST_TYPE *L; 64 | size_t index; 65 | LIST_ELEMENT *Current; 66 | LIST_ELEMENT *Previous; 67 | unsigned timestamp; 68 | DATA_TYPE ElementBuffer; 69 | int (*DlistReplace)(struct _Iterator *,void *data,int direction); 70 | }; 71 | extern INTERFACE(DATA_TYPE) INTERFACE_NAME(DATA_TYPE); 72 | 73 | struct INTERFACE_STRUCT_INTERNAL_NAME(DATA_TYPE) { 74 | size_t (*Size)(const LIST_TYPE *dl); 75 | unsigned (*GetFlags)(const LIST_TYPE *AL); 76 | unsigned (*SetFlags)(LIST_TYPE *AL,unsigned flags); 77 | int (*Clear)(LIST_TYPE *dl); 78 | int (*Contains)(const LIST_TYPE *dl,const DATA_TYPE element); 79 | int (*Erase)(LIST_TYPE *AL,const DATA_TYPE); 80 | int (*EraseAll)(LIST_TYPE *AL,const DATA_TYPE); 81 | int (*Finalize)(LIST_TYPE *AL); 82 | int (*Apply)(LIST_TYPE *L,int(Applyfn)(DATA_TYPE *elem,void *extraArg),void *extraArg); 83 | int (*Equal)(const LIST_TYPE *l1,const LIST_TYPE *l2); 84 | LIST_TYPE *(*Copy)(const LIST_TYPE *dl); 85 | ErrorFunction (*SetErrorFunction)(LIST_TYPE *L,ErrorFunction); 86 | size_t (*Sizeof)(const LIST_TYPE *dl); 87 | Iterator *(*NewIterator)(LIST_TYPE *); 88 | int (*InitIterator)(LIST_TYPE *,void *buf); 89 | int (*deleteIterator)(Iterator *); 90 | size_t (*SizeofIterator)(const LIST_TYPE *); 91 | int (*Save)(const LIST_TYPE *L,FILE *stream, SaveFunction saveFn,void *arg); 92 | LIST_TYPE *(*Load)(FILE *stream, ReadFunction loadFn,void *arg); 93 | size_t (*GetElementSize)(const LIST_TYPE *dl); 94 | 95 | /* -----------------------------------------Sequential container part */ 96 | int (*Add)(LIST_TYPE *dl,const DATA_TYPE newval); 97 | DATA_TYPE *(*GetElement)(const LIST_TYPE *AL,size_t idx); 98 | int (*PushFront)(LIST_TYPE *AL,const DATA_TYPE str); 99 | int (*PopFront)(LIST_TYPE *AL,DATA_TYPE *result); 100 | int (*InsertAt)(LIST_TYPE *AL,size_t idx,const DATA_TYPE newval); 101 | int (*EraseAt)(LIST_TYPE *AL,size_t idx); 102 | int (*ReplaceAt)(LIST_TYPE *AL,size_t idx,const DATA_TYPE newval); 103 | int (*IndexOf)(const LIST_TYPE *AL,const DATA_TYPE SearchedElement,void *args,size_t *result); 104 | 105 | /* ------------------------------------LIST_TYPE container specific part */ 106 | int (*PushBack)(LIST_TYPE *AL,const DATA_TYPE str); 107 | int (*PopBack)(LIST_TYPE *AL,DATA_TYPE *result); 108 | LIST_TYPE *(*Splice)(LIST_TYPE *list,void *pos,LIST_TYPE *toInsert,int direction); 109 | int (*Sort)(LIST_TYPE *l); 110 | int (*Reverse)(LIST_TYPE *l); 111 | LIST_TYPE *(*GetRange)(const LIST_TYPE *l,size_t start,size_t end); 112 | int (*Append)(LIST_TYPE *l1,LIST_TYPE *l2); 113 | CompareFunction (*SetCompareFunction)(LIST_TYPE *l,CompareFunction fn); 114 | int (*UseHeap)(LIST_TYPE *L,const ContainerAllocator *m); 115 | int (*AddRange)(LIST_TYPE *l,size_t n,const DATA_TYPE *data); 116 | LIST_TYPE *(*Create)(size_t elementsize); 117 | LIST_TYPE *(*CreateWithAllocator)(size_t,const ContainerAllocator *); 118 | LIST_TYPE *(*Init)(LIST_TYPE *dlist,size_t elementsize); 119 | LIST_TYPE *(*InitWithAllocator)(LIST_TYPE *L,size_t element_size, const ContainerAllocator *mm); 120 | int (*CopyElement)(const LIST_TYPE *l,size_t idx,DATA_TYPE *outbuf); 121 | int (*InsertIn)(LIST_TYPE *l, size_t idx,LIST_TYPE *newData); 122 | DestructorFunction (*SetDestructor)(LIST_TYPE *v,DestructorFunction fn); 123 | LIST_TYPE *(*InitializeWith)(size_t elementSize, size_t n,const DATA_TYPE *data); 124 | const ContainerAllocator *(*GetAllocator)(const LIST_TYPE *l); 125 | DATA_TYPE *(*Back)(const LIST_TYPE *l); 126 | DATA_TYPE *(*Front)(const LIST_TYPE *l); 127 | int (*RemoveRange)(LIST_TYPE *l,size_t start, size_t end); 128 | int (*RotateLeft)(LIST_TYPE *l, size_t n); 129 | int (*RotateRight)(LIST_TYPE *l,size_t n); 130 | int (*Select)(LIST_TYPE *src,const Mask *m); 131 | LIST_TYPE *(*SelectCopy)(const LIST_TYPE *src,const Mask *m); 132 | LIST_ELEMENT *(*FirstElement)(LIST_TYPE *l); 133 | LIST_ELEMENT *(*LastElement)(LIST_TYPE *l); 134 | LIST_ELEMENT *(*NextElement)(LIST_ELEMENT *le); 135 | LIST_ELEMENT *(*PreviousElement)(LIST_ELEMENT *le); 136 | DATA_TYPE *(*ElementData)(LIST_ELEMENT *le); 137 | int (*SetElementData)(LIST_TYPE *l, LIST_ELEMENT *le,DATA_TYPE data); 138 | DATA_TYPE *(*Advance)(LIST_ELEMENT **pLIST_ELEMENT); 139 | LIST_ELEMENT *(*Skip)(LIST_ELEMENT *l,size_t n); 140 | void *(*MoveBack)(LIST_ELEMENT **pLIST_ELEMENT); 141 | LIST_TYPE *(*SplitAfter)(LIST_TYPE *l, LIST_ELEMENT *pt); 142 | }; 143 | #endif 144 | #endif 145 | -------------------------------------------------------------------------------- /doubledlist.c: -------------------------------------------------------------------------------- 1 | #include "containers.h" 2 | #undef DATA_TYPE 3 | #define DATA_TYPE double 4 | #define COMPARE_EXPRESSION(A, B) (B > A ? -1 : B != A) 5 | #include "dlistgen.c" 6 | #undef DATA_TYPE 7 | -------------------------------------------------------------------------------- /doubledlist.h: -------------------------------------------------------------------------------- 1 | #include "containers.h" 2 | #undef DATA_TYPE 3 | #define DATA_TYPE double 4 | #include "dlistgen.h" 5 | #undef DATA_TYPE 6 | #undef LIST_TYPE 7 | #undef LIST_TYPE_ 8 | #undef INTERFACE 9 | #undef ITERATOR 10 | #undef ITERFACE_NAME 11 | #undef LIST_ELEMENT 12 | #undef LIST_ELEMENT_ 13 | -------------------------------------------------------------------------------- /doublelist.c: -------------------------------------------------------------------------------- 1 | #include "containers.h" 2 | #undef DATA_TYPE 3 | #define DATA_TYPE double 4 | #define COMPARE_EXPRESSION(A, B) (B > A ? -1 : B != A) 5 | #include "listgen.c" 6 | #undef DATA_TYPE 7 | -------------------------------------------------------------------------------- /doublelist.h: -------------------------------------------------------------------------------- 1 | #include "containers.h" 2 | #undef DATA_TYPE 3 | #define DATA_TYPE double 4 | #include "listgen.h" 5 | #undef DATA_TYPE 6 | #undef LIST_TYPE 7 | #undef LIST_TYPE_ 8 | #undef INTERFACE 9 | #undef ITERATOR 10 | #undef ITERFACE_NAME 11 | #undef LIST_ELEMENT 12 | #undef LIST_ELEMENT_ 13 | -------------------------------------------------------------------------------- /error.c: -------------------------------------------------------------------------------- 1 | #include "containers.h" 2 | #include 3 | struct Error { 4 | int code; 5 | char *Message; 6 | } ErrorMessages[] = { 7 | {CONTAINER_ERROR_BADARG, "Bad argument"}, 8 | {CONTAINER_ERROR_NOMEMORY, "Insufficient memory"}, 9 | {CONTAINER_ERROR_INDEX, "Index error"}, 10 | {CONTAINER_ERROR_READONLY, "Object is read only"}, 11 | {CONTAINER_INTERNAL_ERROR, "Internal error in container library"}, 12 | {CONTAINER_ERROR_OBJECT_CHANGED,"Iterator used with modified object"}, 13 | {CONTAINER_ERROR_NOT_EMPTY, "container is not empty"}, 14 | {CONTAINER_ERROR_FILE_READ, "read error in input stream"}, 15 | {CONTAINER_ERROR_FILE_WRITE, "write error in output stream"}, 16 | {CONTAINER_FULL, "Container is full"}, 17 | {CONTAINER_ASSERTION_FAILED, "Assertion failed"}, 18 | {CONTAINER_ERROR_NOENT, "File not found"}, 19 | {CONTAINER_ERROR_FILEOPEN, "Error opening the file"}, 20 | {CONTAINER_ERROR_INCOMPATIBLE, "Incompatible element sizes"}, 21 | {CONTAINER_ERROR_WRONGFILE, "Not a container stream"}, 22 | {CONTAINER_ERROR_NOTIMPLEMENTED,"Function not implemented for this container type"}, 23 | {CONTAINER_ERROR_BADPOINTER, "Debug_malloc: BAD POINTER******"}, 24 | {CONTAINER_ERROR_BUFFEROVERFLOW,"Debug_malloc: BUFFER OVERFLOW******"}, 25 | {CONTAINER_ERROR_WRONGELEMENT, "Wrong element passed to a list"}, 26 | {CONTAINER_ERROR_BADMASK, "Incorrect mask length"}, 27 | {0,"Unknown error"}, 28 | }; 29 | 30 | static char *StrError(int errcode) 31 | { 32 | struct Error *e = ErrorMessages; 33 | while (e->code) { 34 | if (e->code == errcode) 35 | break; 36 | e++; 37 | } 38 | return e->Message; 39 | } 40 | static void *ContainerRaiseError(const char *fnname,int errcode,...) 41 | { 42 | fprintf(stderr,"Container library: Error '%s' in function %s\n",StrError(errcode),fnname); 43 | return NULL; 44 | } 45 | static void *EmptyErrorFunction(const char *fnname,int errcode,...) { return NULL; } 46 | 47 | static ErrorFunction SetError(ErrorFunction n) 48 | { 49 | ErrorFunction old = iError.RaiseError; 50 | if (n != NULL) { 51 | iError.RaiseError = n; 52 | } 53 | return old; 54 | } 55 | 56 | static int BadArgError(const char *fname) 57 | { 58 | iError.RaiseError(fname,CONTAINER_ERROR_BADARG); 59 | return CONTAINER_ERROR_BADARG; 60 | } 61 | 62 | 63 | ErrorInterface iError = { 64 | ContainerRaiseError, 65 | EmptyErrorFunction, 66 | StrError, 67 | SetError, 68 | BadArgError, 69 | }; 70 | 71 | -------------------------------------------------------------------------------- /fgetline.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "containers.h" 5 | #include "ccl_internal.h" 6 | /* This code was adapted from the public domain version of fgetline by C.B. Falconer */ 7 | 8 | static int GetDelim(char **LinePointer, int *n, int delimiter, FILE *stream, ContainerAllocator *mm ) 9 | { 10 | char *p,*newp; 11 | size_t d; 12 | int c; 13 | int len = 0; 14 | 15 | if (stream == NULL || LinePointer == NULL || n == NULL || 16 | (*LinePointer && *n == 0)) { 17 | iError.RaiseError("GetLine",CONTAINER_ERROR_BADARG); 18 | return CONTAINER_ERROR_BADARG; 19 | } 20 | 21 | if (!*LinePointer || !*n) { 22 | p = mm->realloc(*LinePointer, BUFSIZ ); 23 | if (!p) { 24 | iError.RaiseError("GetLine",CONTAINER_ERROR_NOMEMORY); 25 | return CONTAINER_ERROR_NOMEMORY; 26 | } 27 | *n = BUFSIZ; 28 | *LinePointer = p; 29 | } 30 | 31 | else p = *LinePointer; 32 | 33 | /* read until delimiter or EOF */ 34 | while ((c = fgetc( stream )) != EOF) { 35 | if (len >= *n) { 36 | d = p - *LinePointer; 37 | newp = mm->realloc(*LinePointer, *n * 2 ); 38 | if (!newp) 39 | goto NoMem; 40 | p = newp + d; 41 | *LinePointer = newp; 42 | *n *= 2; 43 | } 44 | if (delimiter == c) 45 | break; 46 | *p++ = (char) c; 47 | len++; 48 | if (len == INT_MAX-1) 49 | break; 50 | } 51 | 52 | /* Look for EOF without any bytes read condition */ 53 | if ((c == EOF) && (len == 0)) 54 | return EOF; 55 | 56 | if (len >= *n) { 57 | c = (int)(p - *LinePointer); 58 | newp = mm->realloc( *LinePointer, *n + 1 ); 59 | if (!newp) { 60 | NoMem: 61 | mm->free(*LinePointer); 62 | *LinePointer = NULL; 63 | iError.RaiseError("Getline",CONTAINER_ERROR_NOMEMORY); 64 | return CONTAINER_ERROR_NOMEMORY; 65 | } 66 | p = newp + c; 67 | *LinePointer = newp; 68 | *n += 1; 69 | } 70 | *p = 0; 71 | return len; 72 | } 73 | 74 | int GetLine(char **LinePointer,int *n, FILE *stream,ContainerAllocator *mm) 75 | { 76 | return GetDelim(LinePointer,n,'\n',stream,mm); 77 | } 78 | 79 | static int WGetDelim(wchar_t **LinePointer, int *n, int delimiter, FILE *stream, ContainerAllocator *mm ) 80 | { 81 | wchar_t *p,*newp; 82 | size_t d; 83 | int c; 84 | int len = 0; 85 | 86 | if (stream == NULL || LinePointer == NULL || n == NULL || 87 | (*LinePointer && *n == 0)) { 88 | iError.RaiseError("GetLine",CONTAINER_ERROR_BADARG); 89 | return CONTAINER_ERROR_BADARG; 90 | } 91 | 92 | if (!*LinePointer || !*n) { 93 | p = mm->realloc(*LinePointer, BUFSIZ*sizeof(wchar_t) ); 94 | if (!p) { 95 | iError.RaiseError("GetLine",CONTAINER_ERROR_NOMEMORY); 96 | return CONTAINER_ERROR_NOMEMORY; 97 | } 98 | *n = BUFSIZ; 99 | *LinePointer = p; 100 | } 101 | 102 | else p = *LinePointer; 103 | 104 | /* read until delimiter or EOF */ 105 | while ((c = getwc( stream )) != EOF) { 106 | if (len >= *n) { 107 | d = p - *LinePointer; 108 | newp = mm->realloc(*LinePointer, *n * 2 *sizeof(wchar_t) ); 109 | if (!newp) 110 | goto NoMem; 111 | p = newp + d; 112 | *LinePointer = newp; 113 | *n *= 2; 114 | } 115 | if (delimiter == c) 116 | break; 117 | *p++ = (wchar_t) c; 118 | len++; 119 | if (len == INT_MAX-1) 120 | break; 121 | } 122 | 123 | /* Look for EOF without any bytes read condition */ 124 | if ((c == EOF) && (len == 0)) 125 | return EOF; 126 | 127 | if (len >= *n) { 128 | c = (int)(p - *LinePointer); 129 | newp = mm->realloc( *LinePointer, *n + 1 ); 130 | if (!newp) { 131 | NoMem: 132 | mm->free(*LinePointer); 133 | *LinePointer = NULL; 134 | iError.RaiseError("Getline",CONTAINER_ERROR_NOMEMORY); 135 | return CONTAINER_ERROR_NOMEMORY; 136 | } 137 | p = newp + c; 138 | *LinePointer = newp; 139 | *n += 1; 140 | } 141 | *p = 0; 142 | return len; 143 | } 144 | 145 | int WGetLine(wchar_t **LinePointer,int *n, FILE *stream,ContainerAllocator *mm) 146 | { 147 | return WGetDelim(LinePointer,n,L'\n',stream,mm); 148 | } 149 | 150 | #ifdef TEST 151 | int main(void) 152 | { 153 | char *buf=NULL; 154 | int n=0; 155 | int r = GetLine(&buf,&n,stdin); 156 | printf("'%s'\n",buf); 157 | } 158 | #endif 159 | -------------------------------------------------------------------------------- /generic.c: -------------------------------------------------------------------------------- 1 | #include "containers.h" 2 | #include "ccl_internal.h" 3 | 4 | static size_t Size(const GenericContainer *gen) 5 | { 6 | if (gen == NULL) { 7 | iError.RaiseError("iGeneric.Size",CONTAINER_ERROR_BADARG); 8 | return 0; 9 | } 10 | return gen->vTable->Size(gen); 11 | } 12 | 13 | static unsigned GetFlags(const GenericContainer *gen) 14 | { 15 | if (gen == NULL) { 16 | iError.RaiseError("iGneric.GetFlags",CONTAINER_ERROR_BADARG); 17 | return 0; 18 | } 19 | return gen->vTable->GetFlags(gen); 20 | } 21 | 22 | static unsigned SetFlags(GenericContainer *gen,unsigned newFlags) 23 | { 24 | unsigned result; 25 | if (gen == NULL) { 26 | iError.RaiseError("iGeneric.SetFlags",CONTAINER_ERROR_BADARG); 27 | return 0; 28 | } 29 | result = gen->vTable->GetFlags(gen); 30 | gen->vTable->SetFlags(gen,newFlags); 31 | return result; 32 | } 33 | 34 | static int Clear(GenericContainer *gen) 35 | { 36 | return gen->vTable->Clear(gen); 37 | } 38 | 39 | static int Contains(const GenericContainer *gen,const void *value) 40 | { 41 | return gen->vTable->Contains(gen,value); 42 | } 43 | 44 | static int Erase(GenericContainer *gen,const void *elem) 45 | { 46 | return gen->vTable->Erase(gen,elem); 47 | } 48 | 49 | static int EraseAll(GenericContainer *gen,const void *elem) 50 | { 51 | return gen->vTable->EraseAll(gen,elem); 52 | } 53 | 54 | static int Finalize(GenericContainer *gen) 55 | { 56 | return gen->vTable->Finalize(gen); 57 | } 58 | 59 | static void Apply(GenericContainer *Gen,int (*Applyfn)(void *,void * arg),void *arg) 60 | { 61 | Gen->vTable->Apply(Gen,Applyfn,arg); 62 | } 63 | 64 | static int Equal(const GenericContainer *Gen1,const GenericContainer *Gen2) 65 | { 66 | return Gen1->vTable->Equal(Gen1,Gen2); 67 | } 68 | 69 | static GenericContainer *Copy(const GenericContainer *src) 70 | { 71 | return src->vTable->Copy(src); 72 | } 73 | 74 | static ErrorFunction SetErrorFunction(GenericContainer *Gen,ErrorFunction fn) 75 | { 76 | return Gen->vTable->SetErrorFunction(Gen,fn); 77 | } 78 | 79 | static size_t Sizeof(const GenericContainer *gen) 80 | { 81 | return gen->vTable->Sizeof(gen); 82 | } 83 | 84 | 85 | static Iterator *NewIterator(GenericContainer *gen) 86 | { 87 | return gen->vTable->NewIterator(gen); 88 | } 89 | 90 | 91 | static size_t SizeofIterator(const GenericContainer *gen) 92 | { 93 | return gen->vTable->SizeofIterator(gen); 94 | } 95 | static int InitIterator(GenericContainer *gen,void *buf) 96 | { 97 | return gen->vTable->InitIterator(gen,buf); 98 | } 99 | 100 | 101 | 102 | static int deleteIterator(Iterator *git) 103 | { 104 | GenericIterator *GenIt = (GenericIterator *)git; 105 | GenericContainer *gen = GenIt->Gen; 106 | return gen->vTable->deleteIterator(git); 107 | } 108 | 109 | static int Save(const GenericContainer *gen, FILE *stream,SaveFunction saveFn,void *arg) 110 | { 111 | return gen->vTable->Save(gen,stream,saveFn,arg); 112 | } 113 | 114 | GenericContainerInterface iGeneric = { 115 | Size, 116 | GetFlags, 117 | SetFlags, 118 | Clear, 119 | Contains, 120 | Erase, 121 | EraseAll, 122 | Finalize, 123 | Apply, 124 | Equal, 125 | Copy, 126 | SetErrorFunction, 127 | Sizeof, 128 | NewIterator, 129 | InitIterator, 130 | deleteIterator, 131 | SizeofIterator, 132 | Save, 133 | }; 134 | 135 | -------------------------------------------------------------------------------- /heap.c: -------------------------------------------------------------------------------- 1 | #include "containers.h" 2 | #include "ccl_internal.h" 3 | 4 | #define INVALID_POINTER_VALUE (void *)(~0) 5 | struct tagHeapObject { 6 | HeapInterface *VTable; 7 | unsigned BlockCount; 8 | unsigned CurrentBlock; 9 | unsigned BlockIndex; 10 | char **Heap; 11 | size_t ElementSize; 12 | void *FreeList; 13 | const ContainerAllocator *Allocator; 14 | size_t MemoryUsed; 15 | unsigned timestamp; 16 | }; 17 | #ifndef CHUNK_SIZE 18 | #define CHUNK_SIZE 1000 19 | #endif 20 | /*------------------------------------------------------------------------ 21 | Procedure: new_HeapObject ID:1 22 | Purpose: Allocation of a new list element. If the element 23 | size is zero, we have an heterogenous 24 | list, and we allocate just a pointer to the data 25 | that is maintained by the user. 26 | Note that we allocate the size of a list element 27 | plus the size of the data in a single 28 | block. This block should be passed to the FREE 29 | function. 30 | 31 | Input: The list where the new element should be added and a 32 | pointer to the data that will be added (can be 33 | NULL). 34 | Output: A pointer to the new list element (can be NULL) 35 | Errors: If there is no memory returns NULL 36 | ------------------------------------------------------------------------*/ 37 | static void *newHeapObject(ContainerHeap *l) 38 | { 39 | size_t siz; 40 | char *result; 41 | 42 | if (l->Heap == NULL) { 43 | /* Allocate an array of pointers that will hold the blocks 44 | of CHUNK_SIZE list items 45 | */ 46 | l->Heap = l->Allocator->calloc(CHUNK_SIZE,sizeof(ListElement *)); 47 | if (l->Heap == NULL) { 48 | return NULL; 49 | } 50 | l->MemoryUsed += sizeof(ListElement *)*CHUNK_SIZE; 51 | l->BlockCount = CHUNK_SIZE; 52 | l->CurrentBlock=0; 53 | l->BlockIndex = 0; 54 | } 55 | if (l->FreeList) { 56 | ListElement *le = l->FreeList; 57 | l->FreeList = le->Next; 58 | return le; 59 | } 60 | if (l->BlockIndex >= CHUNK_SIZE) { 61 | /* The current block is full */ 62 | l->CurrentBlock++; 63 | if (l->CurrentBlock == l->BlockCount) { 64 | /* The array of block pointers is full. Allocate CHUNK_SIZE elements more */ 65 | siz = (l->BlockCount+CHUNK_SIZE)*sizeof(ListElement *); 66 | result = l->Allocator->realloc(l->Heap,siz); 67 | if (result == NULL) { 68 | return NULL; 69 | } 70 | l->Heap = (char **)result; 71 | l->MemoryUsed += CHUNK_SIZE*sizeof(ListElement *); 72 | /* Position pointer at the start of the new area */ 73 | result += l->BlockCount*sizeof(ListElement *); 74 | /* Zero the new pointers */ 75 | siz = CHUNK_SIZE*sizeof(ListElement *); 76 | memset(result,0,siz); 77 | l->BlockCount += CHUNK_SIZE; 78 | } 79 | } 80 | if (l->Heap[l->CurrentBlock] == NULL) { 81 | result = l->Allocator->calloc(CHUNK_SIZE,sizeof(void *)+l->ElementSize); 82 | if (result == NULL) { 83 | return NULL; 84 | } 85 | l->Heap[l->CurrentBlock] = result; 86 | l->BlockIndex = 0; 87 | l->MemoryUsed += CHUNK_SIZE * (sizeof(void *) + l->ElementSize); 88 | } 89 | result = l->Heap[l->CurrentBlock]; 90 | result += l->ElementSize * l->BlockIndex; 91 | l->BlockIndex++; 92 | l->timestamp++; 93 | return result; 94 | } 95 | 96 | #ifdef DEBUG_HEAP_FREELIST 97 | static size_t FindBlock(ContainerHeap *heap,void *elem, size_t *idx) 98 | { 99 | size_t i; 100 | intptr_t blockStart,blockEnd,e = (intptr_t)elem; 101 | 102 | for (i=0; i<=heap->BlockIndex;i++) { 103 | blockStart = (intptr_t) heap->Heap[i]; 104 | blockEnd = blockStart + CHUNK_SIZE*sizeof(ListElement *); 105 | if (e >= blockStart && e < blockEnd) { 106 | if (((e-blockStart) % sizeof(ListElement)) == 0) { 107 | *idx = (e-blockStart)/sizeof(ListElement); 108 | return i; 109 | } 110 | else 111 | return 1+heap->BlockIndex; 112 | } 113 | } 114 | return i; 115 | } 116 | #endif 117 | 118 | static int FreeObject(ContainerHeap *heap,void *element) 119 | { 120 | ListElement *le = element; 121 | 122 | le->Next = INVALID_POINTER_VALUE; 123 | #ifdef DEBUG_HEAP_FREELIST 124 | { size_t idx,blockNr; 125 | blockNr = FindBlock(heap,element,&idx); 126 | if (blockNr > heap->CurrentBlock) return -1; 127 | } 128 | #endif 129 | memcpy(le->Data, &heap->FreeList,sizeof(ListElement *)); 130 | heap->FreeList = le; 131 | heap->timestamp++; 132 | return 1; 133 | } 134 | 135 | static void Clear(ContainerHeap * heap) 136 | { 137 | size_t i; 138 | 139 | for (i=0; iBlockCount;i++) heap->Allocator->free(heap->Heap[i]); 140 | heap->Allocator->free(heap->Heap); 141 | heap->BlockCount = 0; 142 | heap->CurrentBlock = 0; 143 | heap->BlockIndex = 0; 144 | heap->Heap = NULL; 145 | heap->MemoryUsed = 0; 146 | heap->timestamp=0; 147 | } 148 | 149 | /*------------------------------------------------------------------------ 150 | Procedure: DestroyListElements ID:1 151 | Purpose: Reclaims all memory used by a list 152 | Input: The list 153 | Output: None 154 | Errors: None 155 | ------------------------------------------------------------------------*/ 156 | static void DestroyHeap(ContainerHeap *l) 157 | { 158 | Clear(l); 159 | l->Allocator->free(l); 160 | } 161 | 162 | static size_t GetHeapSize(ContainerHeap *heap) 163 | { 164 | size_t result; 165 | 166 | if (heap->Heap == NULL) 167 | return 0; 168 | result = CHUNK_SIZE * (heap->CurrentBlock+1) * heap->ElementSize; 169 | result += heap->BlockIndex * (heap->ElementSize); 170 | result += (sizeof(void *) * heap->BlockCount); 171 | return result; 172 | } 173 | 174 | static ContainerHeap *InitHeap(void *pHeap,size_t ElementSize,const ContainerAllocator *m) 175 | { 176 | ContainerHeap *heap = pHeap; 177 | memset(heap,0,sizeof(*heap)); 178 | heap->VTable = &iHeap; 179 | if (ElementSize < 2*sizeof(ListElement *)) 180 | ElementSize = 2*sizeof(ListElement *); 181 | heap->ElementSize = ElementSize; 182 | if (m == NULL) 183 | m = CurrentAllocator; 184 | heap->Allocator = m; 185 | return heap; 186 | } 187 | 188 | static ContainerHeap *newHeap(size_t ElementSize,const ContainerAllocator *m) 189 | { 190 | ContainerHeap *result = m->malloc(sizeof(ContainerHeap)); 191 | if (result == NULL) 192 | return NULL; 193 | return InitHeap(result,ElementSize,m); 194 | } 195 | 196 | struct HeapIterator { 197 | Iterator it; 198 | ContainerHeap *Heap; 199 | size_t BlockNumber; 200 | size_t BlockPosition; 201 | size_t timestamp; 202 | unsigned long Flags; 203 | 204 | } ; 205 | 206 | static int SkipFreeForward(struct HeapIterator *it) 207 | { 208 | size_t idx = it->BlockNumber * CHUNK_SIZE + it->BlockPosition; 209 | size_t start = idx; 210 | ListElement *le; 211 | char *p; 212 | 213 | p = it->Heap->Heap[it->BlockNumber]; 214 | p += it->BlockPosition*it->Heap->ElementSize; 215 | le = (ListElement *)p; 216 | 217 | while (le->Next == INVALID_POINTER_VALUE) { 218 | idx++; 219 | it->BlockPosition++; 220 | if (it->BlockPosition >= CHUNK_SIZE) { 221 | it->BlockNumber++; 222 | if (it->BlockNumber >= it->Heap->BlockCount) 223 | return -1; 224 | p = it->Heap->Heap[it->BlockNumber]; 225 | it->BlockPosition = 0; 226 | } 227 | else { 228 | /* Do not go beyond the last position in the last block */ 229 | if (it->BlockNumber == it->Heap->BlockCount && 230 | it->BlockPosition >= it->Heap->BlockIndex) 231 | return -1; 232 | p = it->Heap->Heap[it->BlockNumber]; 233 | p += (it->BlockPosition)*it->Heap->ElementSize; 234 | } 235 | le = (ListElement *)p; 236 | } 237 | if (idx == start) return 0; 238 | return 1; 239 | } 240 | 241 | static int SkipFreeBackwards(struct HeapIterator *it) 242 | { 243 | size_t idx = it->Heap->CurrentBlock * CHUNK_SIZE + it->Heap->BlockIndex; 244 | size_t start = idx; 245 | ListElement *le; 246 | char *p; 247 | 248 | p = it->Heap->Heap[it->BlockNumber]; 249 | p += it->BlockPosition*it->Heap->ElementSize; 250 | le = (ListElement *)p; 251 | 252 | while (le->Next == INVALID_POINTER_VALUE) { 253 | idx--; 254 | if (it->Heap->BlockIndex > 0) { 255 | p -= it->Heap->ElementSize; 256 | it->BlockPosition--; 257 | } 258 | else { 259 | if (it->BlockNumber == 0) 260 | return -1; 261 | it->BlockNumber--; 262 | it->BlockPosition = CHUNK_SIZE-1; 263 | p = it->Heap->Heap[it->BlockNumber]; 264 | p += (CHUNK_SIZE-1)*it->Heap->ElementSize; 265 | } 266 | le = (ListElement *)p; 267 | } 268 | if (idx == start) return 0; 269 | return 1; 270 | } 271 | 272 | static void *GetFirst(Iterator *it) 273 | { 274 | struct HeapIterator *hi = (struct HeapIterator *)it; 275 | ContainerHeap *heap = hi->Heap; 276 | char *result; 277 | int r; 278 | 279 | hi->BlockNumber = hi->BlockPosition = 0; 280 | if (heap->BlockCount == 0) 281 | return NULL; 282 | r = SkipFreeForward(hi); 283 | if (r < 0) return NULL; 284 | result = heap->Heap[hi->BlockNumber]; 285 | result += (hi->BlockPosition*heap->ElementSize); 286 | if (r == 0) hi->BlockPosition++; 287 | return result; 288 | } 289 | 290 | 291 | static void *GetNext(Iterator *it) 292 | { 293 | struct HeapIterator *hi = (struct HeapIterator *)it; 294 | ContainerHeap *heap = hi->Heap; 295 | char *result; 296 | 297 | if (hi->BlockNumber == (heap->CurrentBlock)) { 298 | /* In the last block we should not got beyond the 299 | last used element, the block can be half full. 300 | */ 301 | if (hi->BlockPosition >= heap->BlockIndex) 302 | return NULL; 303 | } 304 | /* 305 | We are in a block that is full. Check that the position 306 | is less than the size of the block. 307 | */ 308 | if (hi->BlockPosition >= CHUNK_SIZE) { 309 | hi->BlockNumber++; 310 | hi->BlockPosition = 0; 311 | return GetNext(it); 312 | } 313 | if (SkipFreeForward(hi) < 0) 314 | return NULL; 315 | result = heap->Heap[hi->BlockNumber]; 316 | result += (hi->BlockPosition*heap->ElementSize); 317 | hi->BlockPosition++; 318 | return result; 319 | } 320 | 321 | static size_t GetPosition(Iterator *it) 322 | { 323 | struct HeapIterator *hi = (struct HeapIterator *)it; 324 | return hi->BlockNumber*CHUNK_SIZE + hi->BlockPosition; 325 | } 326 | 327 | static void *GetPrevious(Iterator *it) 328 | { 329 | struct HeapIterator *hi = (struct HeapIterator *)it; 330 | ContainerHeap *heap = hi->Heap; 331 | char *result; 332 | int r; 333 | 334 | if (hi->BlockPosition == 0) { 335 | /* Go to the last element of the previous block */ 336 | if (hi->BlockNumber == 0) 337 | return NULL; 338 | hi->BlockNumber--; 339 | hi->BlockPosition = CHUNK_SIZE -1; 340 | result = heap->Heap[hi->BlockNumber]; 341 | result += (hi->BlockPosition*heap->ElementSize); 342 | return result; 343 | } 344 | r = SkipFreeBackwards(hi); 345 | if (r < 0) 346 | return NULL; 347 | if (r == 0) hi->BlockPosition--; 348 | result = heap->Heap[hi->BlockNumber]; 349 | result += (hi->BlockPosition*heap->ElementSize); 350 | return result; 351 | } 352 | 353 | static void *GetLast(Iterator *it) 354 | { 355 | struct HeapIterator *hi = (struct HeapIterator *)it; 356 | ContainerHeap *heap = hi->Heap; 357 | char *result; 358 | if (heap->BlockCount == 0) 359 | return NULL; 360 | hi->BlockNumber = heap->CurrentBlock; 361 | hi->BlockPosition = heap->BlockIndex-1; 362 | result = heap->Heap[heap->CurrentBlock]; 363 | result += (hi->BlockPosition) *heap->ElementSize; 364 | return result; 365 | } 366 | 367 | static void *GetCurrent(Iterator *it) 368 | { 369 | struct HeapIterator *hi = (struct HeapIterator *)it; 370 | ContainerHeap *heap = hi->Heap; 371 | char *result; 372 | if (heap->BlockCount == 0) 373 | return NULL; 374 | result = heap->Heap[hi->BlockNumber]; 375 | result += (hi->BlockPosition) *heap->ElementSize; 376 | return result; 377 | } 378 | 379 | static Iterator *NewIterator(ContainerHeap *heap) 380 | { 381 | struct HeapIterator *result; 382 | 383 | if (heap == NULL) { 384 | iError.RaiseError("iHeap.NewIterator",CONTAINER_ERROR_BADARG); 385 | return NULL; 386 | } 387 | result = heap->Allocator->calloc(1,sizeof(struct HeapIterator)); 388 | if (result == NULL) 389 | return NULL; 390 | result->Heap = heap; 391 | result->timestamp = heap->CurrentBlock+heap->BlockIndex; 392 | result->it.GetFirst = GetFirst; 393 | result->it.GetNext = GetNext; 394 | result->it.GetPrevious = GetPrevious; 395 | result->it.GetCurrent = GetCurrent; 396 | result->it.GetLast = GetLast; 397 | result->it.GetPosition = GetPosition; 398 | return &result->it; 399 | } 400 | 401 | static int deleteIterator(Iterator *it) 402 | { 403 | struct HeapIterator *hi = (struct HeapIterator *)it; 404 | ContainerHeap *heap = hi->Heap; 405 | heap->Allocator->free(it); 406 | return 1; 407 | } 408 | 409 | HeapInterface iHeap = { 410 | newHeap, 411 | newHeapObject, 412 | FreeObject, 413 | Clear, 414 | DestroyHeap, 415 | InitHeap, 416 | GetHeapSize, 417 | NewIterator, 418 | deleteIterator 419 | }; 420 | -------------------------------------------------------------------------------- /iMask.c: -------------------------------------------------------------------------------- 1 | #include "containers.h" 2 | #include "ccl_internal.h" 3 | 4 | static Mask *CreateFromMask(size_t n,char *data) 5 | { 6 | Mask *result = CurrentAllocator->malloc(n+sizeof(Mask)); 7 | if (result == NULL) { 8 | iError.RaiseError("iMask.Copy",CONTAINER_ERROR_NOMEMORY); 9 | return NULL; 10 | } 11 | if (data) memcpy(result->data,data,n); 12 | else memset(result->data,0,n); 13 | result->Allocator = CurrentAllocator; 14 | result->length = n; 15 | return result; 16 | } 17 | 18 | static Mask *Copy(Mask *src) 19 | { 20 | Mask *result; 21 | if (src == NULL) return NULL; 22 | result = CreateFromMask(src->length, src->data); 23 | if (result) { 24 | result->Allocator = src->Allocator; 25 | } 26 | return result; 27 | } 28 | 29 | static Mask *Create(size_t n) 30 | { 31 | return CreateFromMask(n,NULL); 32 | } 33 | 34 | static int Set(Mask *m,size_t idx,int val) 35 | { 36 | if (idx >= m->length) { 37 | iError.RaiseError("iMask.Set",CONTAINER_ERROR_INDEX,m,idx); 38 | return CONTAINER_ERROR_INDEX; 39 | } 40 | m->data[idx]=(char)val; 41 | return 1; 42 | } 43 | 44 | static int Clear(Mask *m) 45 | { 46 | memset(m->data,0,m->length); 47 | m->length=0; 48 | return 1; 49 | } 50 | 51 | static int Finalize(Mask *m) 52 | { 53 | m->Allocator->free(m); 54 | return 1; 55 | } 56 | 57 | static size_t Size(Mask *m) 58 | { 59 | return (m == NULL) ? 0 : m->length; 60 | } 61 | 62 | static int Verify(const Mask *src1, const Mask *src2,const char *name) 63 | { 64 | if (src1 == NULL || src2 == NULL) { 65 | return iError.NullPtrError(name); 66 | } 67 | if (src1->length != src2->length) { 68 | iError.RaiseError(name,CONTAINER_ERROR_INCOMPATIBLE); 69 | return CONTAINER_ERROR_INCOMPATIBLE; 70 | } 71 | return 0; 72 | } 73 | 74 | static int And(Mask *src1,Mask *src2) 75 | { 76 | size_t i; 77 | int r = Verify(src1,src2,"iMask.And"); 78 | 79 | if (r) return r; 80 | for (i=0; ilength;i++) { 81 | src1->data[i] &= src2->data[i]; 82 | } 83 | return 1; 84 | } 85 | 86 | static int Not(Mask *src1) 87 | { 88 | size_t i; 89 | 90 | if (src1 == NULL ) { 91 | return iError.NullPtrError("iMask.And"); 92 | } 93 | for (i=0; ilength;i++) { 94 | src1->data[i] = src1->data[i] ? 0 : 1; 95 | } 96 | return 1; 97 | } 98 | 99 | 100 | static int Or(Mask *src1,Mask *src2) 101 | { 102 | size_t i; 103 | int r = Verify(src1,src2,"iMask.or"); 104 | 105 | if (r) return r; 106 | for (i=0; ilength;i++) { 107 | src1->data[i] |= src2->data[i]; 108 | } 109 | return 1; 110 | } 111 | 112 | static size_t Sizeof(Mask *m) 113 | { 114 | if (m == NULL) return sizeof(Mask); 115 | return sizeof(Mask) + m->length; 116 | } 117 | 118 | static size_t PopulationCount(const Mask *m) 119 | { 120 | size_t i,result=0; 121 | 122 | for (i=0; ilength;i++) { 123 | if (m->data[i]) result++; 124 | } 125 | return result; 126 | } 127 | 128 | MaskInterface iMask = { 129 | And, 130 | Or, 131 | Not, 132 | CreateFromMask, 133 | Create, 134 | Copy, 135 | Size, 136 | Sizeof, 137 | Set, 138 | Clear, 139 | Finalize, 140 | PopulationCount, 141 | }; 142 | -------------------------------------------------------------------------------- /intdlist.c: -------------------------------------------------------------------------------- 1 | #include "containers.h" 2 | #undef DATA_TYPE 3 | #define DATA_TYPE int 4 | #define COMPARE_EXPRESSION(A, B) ((*B)->Data > (*A)->Data ? -1 : (*B)->Data != (*A)->Data) 5 | #include "dlistgen.c" 6 | #undef DATA_TYPE 7 | -------------------------------------------------------------------------------- /intdlist.h: -------------------------------------------------------------------------------- 1 | #include "containers.h" 2 | #undef DATA_TYPE 3 | #define DATA_TYPE int 4 | #include "dlistgen.h" 5 | #undef DATA_TYPE 6 | #undef LIST_TYPE 7 | #undef LIST_TYPE_ 8 | #undef INTERFACE 9 | #undef ITERATOR 10 | #undef ITERFACE_NAME 11 | #undef LIST_ELEMENT 12 | #undef LIST_ELEMENT_ 13 | -------------------------------------------------------------------------------- /intlist.c: -------------------------------------------------------------------------------- 1 | #include "containers.h" 2 | #undef DATA_TYPE 3 | #define DATA_TYPE int 4 | #define COMPARE_EXPRESSION(A, B) ((*B)->Data > (*A)->Data ? -1 : (*B)->Data != (*A)->Data) 5 | #include "listgen.c" 6 | #undef DATA_TYPE 7 | -------------------------------------------------------------------------------- /intlist.h: -------------------------------------------------------------------------------- 1 | #include "containers.h" 2 | #undef DATA_TYPE 3 | #define DATA_TYPE int 4 | #include "listgen.h" 5 | #undef DATA_TYPE 6 | #undef LIST_TYPE 7 | #undef LIST_TYPE_ 8 | #undef INTERFACE 9 | #undef ITERATOR 10 | #undef ITERFACE_NAME 11 | #undef LIST_ELEMENT 12 | #undef LIST_ELEMENT_ 13 | -------------------------------------------------------------------------------- /listgen.h: -------------------------------------------------------------------------------- 1 | #ifndef DATA_TYPE 2 | #error "The symbol DATA_TYPE MUST be defined" 3 | #else 4 | #ifndef DEFAULT_START_SIZE 5 | #define DEFAULT_START_SIZE 20 6 | #endif 7 | #ifndef INT_MAX 8 | #define INT_MAX (((unsigned)-1) >> 1) 9 | #endif 10 | #undef LIST_TYPE 11 | #undef LIST_TYPE_ 12 | #undef INTERFACE 13 | #undef ITERATOR 14 | #undef ITERFACE_NAME 15 | 16 | #define CONCAT(x,y) x ## y 17 | #define CONCAT3_(a,b,c) a##b##c 18 | #define CONCAT3(a,b,c) CONCAT3_(a,b,c) 19 | #define EVAL(t) t 20 | #define INTERFACE(t) CONCAT(t,ListInterface) 21 | #define ITERATOR(t) CONCAT(t,ListIterator) 22 | #define ERROR_RETURN 0 23 | 24 | #define LIST_TYPE_(t) CONCAT(t,List) 25 | #define LIST_TYPE LIST_TYPE_(DATA_TYPE) 26 | #define INTERFACE_NAME(a) CONCAT3(i,EVAL(a),List) 27 | #define LIST_STRUCT_INTERNAL_NAME(a) CONCAT3(__,EVAL(a),List) 28 | #define INTERFACE_STRUCT_INTERNAL_NAME(a) CONCAT3(__,EVAL(a),ListInterface) 29 | 30 | typedef struct LIST_ELEMENT { 31 | struct LIST_ELEMENT *Next; 32 | #ifdef SPARC32 33 | void *alignment; 34 | #endif 35 | DATA_TYPE Data; 36 | } LIST_ELEMENT; 37 | 38 | typedef struct LIST_STRUCT_INTERNAL_NAME(DATA_TYPE) LIST_TYPE; 39 | typedef struct INTERFACE_STRUCT_INTERNAL_NAME(DATA_TYPE) INTERFACE(DATA_TYPE); 40 | struct LIST_STRUCT_INTERNAL_NAME(DATA_TYPE) { 41 | INTERFACE(DATA_TYPE) *VTable; /* Methods table */ 42 | size_t count; /* in elements units */ 43 | unsigned Flags; 44 | unsigned timestamp; /* Changed at each modification */ 45 | size_t ElementSize; /* Size (in bytes) of each element */ 46 | LIST_ELEMENT *Last; /* The last item */ 47 | LIST_ELEMENT *First; /* The contents of the list start here */ 48 | CompareFunction Compare; /* Element comparison function */ 49 | ErrorFunction RaiseError; /* Error function */ 50 | ContainerHeap *Heap; 51 | const ContainerAllocator *Allocator; 52 | DestructorFunction DestructorFn; 53 | }; 54 | 55 | struct ITERATOR(DATA_TYPE) { 56 | Iterator it; 57 | LIST_TYPE *L; 58 | size_t index; 59 | LIST_ELEMENT *Current; 60 | LIST_ELEMENT *Previous; 61 | unsigned timestamp; 62 | DATA_TYPE ElementBuffer; 63 | int (*ListReplace)(struct _Iterator *,void *data,int direction); 64 | }; 65 | extern INTERFACE(DATA_TYPE) INTERFACE_NAME(DATA_TYPE); 66 | 67 | struct INTERFACE_STRUCT_INTERNAL_NAME(DATA_TYPE) { 68 | size_t (*Size)(const LIST_TYPE *L); 69 | unsigned (*GetFlags)(const LIST_TYPE *L); 70 | unsigned (*SetFlags)(LIST_TYPE *L,unsigned flags); 71 | int (*Clear)(LIST_TYPE *L); 72 | int (*Contains)(const LIST_TYPE *L,const DATA_TYPE element); 73 | int (*Erase)(LIST_TYPE *L,const DATA_TYPE); 74 | int (*EraseAll)(LIST_TYPE *l,const DATA_TYPE); 75 | int (*Finalize)(LIST_TYPE *L); 76 | int (*Apply)(LIST_TYPE *L,int(Applyfn)(DATA_TYPE *,void *),void *arg); 77 | int (*Equal)(const LIST_TYPE *l1,const LIST_TYPE *l2); 78 | LIST_TYPE *(*Copy)(const LIST_TYPE *L); 79 | ErrorFunction (*SetErrorFunction)(LIST_TYPE *L,ErrorFunction); 80 | size_t (*Sizeof)(const LIST_TYPE *l); 81 | Iterator *(*NewIterator)(LIST_TYPE *L); 82 | int (*InitIterator)(LIST_TYPE *L,void *buf); 83 | int (*deleteIterator)(Iterator *); 84 | size_t (*SizeofIterator)(const LIST_TYPE *); 85 | int (*Save)(const LIST_TYPE *L,FILE *stream, SaveFunction saveFn,void *arg); 86 | LIST_TYPE *(*Load)(FILE *stream, ReadFunction loadFn,void *arg); 87 | size_t (*GetElementSize)(const LIST_TYPE *l); 88 | /* -------------------------------------------This is the Sequential container part */ 89 | int (*Add)(LIST_TYPE *L,const DATA_TYPE newval); 90 | DATA_TYPE *(*GetElement)(const LIST_TYPE *L,size_t idx); 91 | int (*PushFront)(LIST_TYPE *L,const DATA_TYPE str); 92 | int (*PopFront)(LIST_TYPE *L,DATA_TYPE *result); 93 | int (*InsertAt)(LIST_TYPE *L,size_t idx,const DATA_TYPE newval); 94 | int (*EraseAt)(LIST_TYPE *L,size_t idx); 95 | int (*ReplaceAt)(LIST_TYPE *L,size_t idx,const DATA_TYPE newval); 96 | int (*IndexOf)(const LIST_TYPE *L,const DATA_TYPE SearchedElement,void *ExtraArgs,size_t *result); 97 | /* -------------------------------------------This is the list container part */ 98 | int (*InsertIn)(LIST_TYPE *l, size_t idx,LIST_TYPE *newData); 99 | int (*CopyElement)(const LIST_TYPE *list,size_t idx,DATA_TYPE *OutBuffer); 100 | int (*EraseRange)(LIST_TYPE *L,size_t start,size_t end); 101 | int (*Sort)(LIST_TYPE *l); 102 | int (*Reverse)(LIST_TYPE *l); 103 | LIST_TYPE *(*GetRange)(const LIST_TYPE *l,size_t start,size_t end); 104 | int (*Append)(LIST_TYPE *l1,LIST_TYPE *l2); 105 | CompareFunction (*SetCompareFunction)(LIST_TYPE *l,CompareFunction fn); 106 | CompareFunction Compare; 107 | int (*UseHeap)(LIST_TYPE *L, const ContainerAllocator *m); 108 | int (*AddRange)(LIST_TYPE *L, size_t n,const DATA_TYPE *data); 109 | LIST_TYPE *(*Create)(void); 110 | LIST_TYPE *(*CreateWithAllocator)(const ContainerAllocator *mm); 111 | LIST_TYPE *(*Init)(LIST_TYPE *aList); 112 | LIST_TYPE *(*InitWithAllocator)(LIST_TYPE *aList,const ContainerAllocator *mm); 113 | const ContainerAllocator *(*GetAllocator)(const LIST_TYPE *list); 114 | DestructorFunction (*SetDestructor)(LIST_TYPE *v,DestructorFunction fn); 115 | LIST_TYPE *(*InitializeWith)(size_t n,const void *data); 116 | DATA_TYPE *(*Back)(const LIST_TYPE *l); 117 | DATA_TYPE *(*Front)(const LIST_TYPE *l); 118 | int (*RemoveRange)(LIST_TYPE *l,size_t start, size_t end); 119 | int (*RotateLeft)(LIST_TYPE *l, size_t n); 120 | int (*RotateRight)(LIST_TYPE *l,size_t n); 121 | int (*Select)(LIST_TYPE *src,const Mask *m); 122 | LIST_TYPE *(*SelectCopy)(const LIST_TYPE *src,const Mask *m); 123 | LIST_ELEMENT *(*FirstElement)(LIST_TYPE *l); 124 | LIST_ELEMENT *(*LastElement)(LIST_TYPE *l); 125 | LIST_ELEMENT *(*NextElement)(LIST_ELEMENT *le); 126 | DATA_TYPE *(*ElementData)(LIST_ELEMENT *le); 127 | int (*SetElementData)(LIST_TYPE *l, LIST_ELEMENT *le,DATA_TYPE data); 128 | DATA_TYPE *(*Advance)(LIST_ELEMENT **); 129 | LIST_ELEMENT *(*Skip)(LIST_ELEMENT *l,size_t n); 130 | LIST_TYPE *(*SplitAfter)(LIST_TYPE *l, LIST_ELEMENT *pt); 131 | }; 132 | #endif 133 | -------------------------------------------------------------------------------- /longlongdlist.c: -------------------------------------------------------------------------------- 1 | #include "containers.h" 2 | #undef DATA_TYPE 3 | typedef long long longlong; 4 | #define DATA_TYPE longlong 5 | #define COMPARE_EXPRESSION(A, B) (B > A ? -1 : B != A) 6 | #include "dlistgen.c" 7 | #undef DATA_TYPE 8 | -------------------------------------------------------------------------------- /longlongdlist.h: -------------------------------------------------------------------------------- 1 | #include "containers.h" 2 | #undef DATA_TYPE 3 | typedef long long longlong; 4 | #define DATA_TYPE longlong 5 | #include "dlistgen.h" 6 | #undef DATA_TYPE 7 | #undef LIST_TYPE 8 | #undef LIST_TYPE_ 9 | #undef INTERFACE 10 | #undef ITERATOR 11 | #undef ITERFACE_NAME 12 | #undef LIST_ELEMENT 13 | #undef LIST_ELEMENT_ 14 | -------------------------------------------------------------------------------- /longlonglist.c: -------------------------------------------------------------------------------- 1 | #include "containers.h" 2 | #undef DATA_TYPE 3 | typedef long long longlong; 4 | #define DATA_TYPE longlong 5 | #define COMPARE_EXPRESSION(A, B) (B > A ? -1 : B != A) 6 | #include "listgen.c" 7 | #undef DATA_TYPE 8 | -------------------------------------------------------------------------------- /longlonglist.h: -------------------------------------------------------------------------------- 1 | #include "containers.h" 2 | #undef DATA_TYPE 3 | typedef long long longlong; 4 | #define DATA_TYPE longlong 5 | #include "listgen.h" 6 | #undef DATA_TYPE 7 | #undef LIST_TYPE 8 | #undef LIST_TYPE_ 9 | #undef INTERFACE 10 | #undef ITERATOR 11 | #undef ITERFACE_NAME 12 | #undef LIST_ELEMENT 13 | #undef LIST_ELEMENT_ 14 | -------------------------------------------------------------------------------- /malloc_debug.c: -------------------------------------------------------------------------------- 1 | /* 2 | This is a thin layer based on malloc/free. It checks for 3 | (1) freeing a bloack that wasn't allocated with this utility 4 | (2) Freeing twice a block 5 | (3) Freeing a block that contains a memory overwrite past its allocated limit 6 | Besides this, it contains an API for finding out the size of a block 7 | Block layout: 8 | |----------|-----------|--------------- ... ------------------|-------| 9 | |Signature | Size | user memory of requested size | MAGIC | 10 | +----------+-----------+--------------------------------------+-------| 11 | lower addresses higher addresses 12 | */ 13 | #include "containers.h" 14 | #define SIGNATURE 0xdeadbeef 15 | #define MAGIC 0xbeefdead 16 | static size_t AllocatedMemory; 17 | #define ALIGN(size, boundary) (((size) + ((boundary) - 1)) & ~((boundary) - 1)) 18 | #define ALIGN_DEFAULT(size) ALIGN(size,sizeof(size_t)) 19 | static void *Malloc(size_t size) 20 | { 21 | register char *r; 22 | register size_t *ip = NULL; 23 | size = ALIGN_DEFAULT(size); 24 | size += 3 * sizeof(size_t); 25 | r = malloc(size); 26 | if (r == NULL) 27 | return NULL; 28 | AllocatedMemory += size; 29 | ip = (size_t *) r; 30 | *ip++ = SIGNATURE; 31 | *ip++ = size; 32 | memset(ip, 0, size - 3*sizeof(size_t)); 33 | ip = (size_t *) (&r[size - sizeof(size_t)]); 34 | *ip = MAGIC; 35 | return (r + 2 * sizeof(size_t)); 36 | } 37 | static void Free(void *pp) 38 | { 39 | size_t *ip = NULL; 40 | size_t s; 41 | register char *p = pp; 42 | if (p == NULL) 43 | return; 44 | p -= 2 * sizeof(size_t); 45 | ip = (size_t *) p; 46 | if (*ip == SIGNATURE) { 47 | *ip++ = 0; 48 | s = *ip; 49 | ip = (size_t *) (&p[s - sizeof(size_t)]); 50 | if (*ip != MAGIC) { 51 | /* overwritten block size %d\n */ 52 | iError.RaiseError("Free",CONTAINER_ERROR_BUFFEROVERFLOW); 53 | return; 54 | } 55 | *ip = 0; 56 | AllocatedMemory -= s; 57 | memset(p,66,s); 58 | free(p); 59 | } 60 | else { 61 | /* Wrong block passed to Free */ 62 | iError.RaiseError("Free",CONTAINER_ERROR_BADPOINTER); 63 | } 64 | } 65 | 66 | static void *Realloc(void *ptr,size_t newsize) 67 | { 68 | size_t oldsize; 69 | size_t *ip; 70 | void *result; 71 | 72 | if (ptr == NULL) 73 | return Malloc(newsize); 74 | ip = ptr; 75 | oldsize = *--ip; 76 | if (*--ip != SIGNATURE) { 77 | /* Wrong block passed to Free */ 78 | iError.RaiseError("Realloc",CONTAINER_ERROR_BADPOINTER); 79 | return NULL; 80 | } 81 | newsize = ALIGN_DEFAULT(newsize); 82 | oldsize -= 3*sizeof(size_t); 83 | if (oldsize == newsize) 84 | return ptr; 85 | ip++; 86 | if (newsize < oldsize) { 87 | char *p; 88 | *ip++ = newsize; 89 | p = (char *)ip; 90 | p += newsize - sizeof(size_t); 91 | ip = (size_t *)p; 92 | *ip = MAGIC; 93 | return ptr; 94 | } 95 | result = Malloc(newsize); 96 | if (result) { 97 | memcpy(result,ptr,oldsize); 98 | Free(ptr); 99 | } 100 | return result; 101 | } 102 | 103 | static void *Calloc(size_t n,size_t siz) 104 | { 105 | size_t totalSize = n * siz; 106 | return Malloc(totalSize); 107 | } 108 | 109 | ContainerAllocator iDebugMalloc = { 110 | Malloc, 111 | Free, 112 | Realloc, 113 | Calloc, 114 | }; 115 | -------------------------------------------------------------------------------- /memorymanager.c: -------------------------------------------------------------------------------- 1 | #include "containers.h" 2 | static ContainerAllocator DefaultAllocatorObject = { malloc,free,realloc,calloc}; 3 | ContainerAllocator *CurrentAllocator = &DefaultAllocatorObject; 4 | ContainerAllocator *SetCurrentAllocator(ContainerAllocator *in) 5 | { 6 | ContainerAllocator *c; 7 | if (in == NULL) 8 | return CurrentAllocator; 9 | c = CurrentAllocator; 10 | CurrentAllocator = in; 11 | return c; 12 | } 13 | 14 | -------------------------------------------------------------------------------- /observer.c: -------------------------------------------------------------------------------- 1 | #include "containers.h" 2 | #include "ccl_internal.h" 3 | typedef struct _tagObserver { 4 | void *ObservedObject; /* The object being observed */ 5 | ObserverFunction Callback; /* The function to call */ 6 | unsigned Flags; /* The events the observer wishes to be informed about */ 7 | } Observer; 8 | 9 | static Observer *ObserverVector; 10 | static size_t vsize; 11 | #define CHUNK_SIZE 25 12 | 13 | static int Subscribe(void *ObservedObject, ObserverFunction callback, unsigned flags) 14 | { 15 | size_t i; 16 | Observer *pObs=NULL; 17 | GenericContainer *gen = ObservedObject; 18 | unsigned Subjectflags = gen->Flags; 19 | 20 | Subjectflags |= CONTAINER_HAS_OBSERVER; 21 | gen->Flags=Subjectflags; 22 | if (ObserverVector == NULL) { 23 | ObserverVector = calloc(sizeof(Observer),CHUNK_SIZE); 24 | if (ObserverVector == NULL) { 25 | iError.RaiseError("iObserver.Subscribe",CONTAINER_ERROR_NOMEMORY); 26 | return CONTAINER_ERROR_NOMEMORY; 27 | } 28 | vsize = CHUNK_SIZE; 29 | } 30 | for (i=0; i= vsize) { 37 | Observer *tmp = realloc(ObserverVector,(vsize+CHUNK_SIZE)*sizeof(Observer)); 38 | if (tmp == NULL) { 39 | iError.RaiseError("iObserver.Subscribe",CONTAINER_ERROR_NOMEMORY); 40 | return CONTAINER_ERROR_NOMEMORY; 41 | } 42 | ObserverVector = tmp; 43 | memset(ObserverVector+vsize+1,0,(CHUNK_SIZE-1)*sizeof(Observer)); 44 | pObs = ObserverVector + vsize; 45 | vsize+= CHUNK_SIZE; 46 | } 47 | pObs->ObservedObject = ObservedObject; 48 | pObs->Callback = callback; 49 | pObs->Flags = flags; 50 | return 1; 51 | } 52 | 53 | 54 | static int Notify(const void *ObservedObject,unsigned operation,const void *ExtraInfo1,const void *ExtraInfo2) 55 | { 56 | int count=0; 57 | size_t idx; 58 | const void *ExtraInfo[2]; 59 | 60 | ExtraInfo[0] = ExtraInfo1; 61 | ExtraInfo[1] = ExtraInfo2; 62 | for (idx=0; idx < vsize;idx++) { 63 | if (ObserverVector[idx].ObservedObject == ObservedObject) { 64 | if (ObserverVector[idx].Flags & operation) { 65 | ObserverVector[idx].Callback(ObservedObject,operation,ExtraInfo); 66 | count++; 67 | } 68 | } 69 | } 70 | return count; 71 | } 72 | 73 | static size_t Unsubscribe(void *ObservedObject,ObserverFunction callback) 74 | { 75 | size_t idx=0,count=0; 76 | 77 | if (ObservedObject == NULL) { 78 | /* Erase all observers that have the specified function. This means that the 79 | object receiving the callback goes out of scope */ 80 | if (callback) /* If both are NULL do nothing */ 81 | for (; idx 35 | 36 | typedef int cmp_t(void *, const void *, const void *); 37 | static inline char *med3(char *, char *, char *, cmp_t *, void *); 38 | static inline void swapfunc(char *, char *, int, int); 39 | 40 | #define min(a, b) (a) < (b) ? a : b 41 | 42 | /* 43 | * Qsort routine from Bentley & McIlroy's "Engineering a Sort Function". 44 | */ 45 | #define swapcode(TYPE, parmi, parmj, n) { \ 46 | long i = (n) / sizeof (TYPE); \ 47 | TYPE *pi = (TYPE *) (parmi); \ 48 | TYPE *pj = (TYPE *) (parmj); \ 49 | do { \ 50 | TYPE t = *pi; \ 51 | *pi++ = *pj; \ 52 | *pj++ = t; \ 53 | } while (--i > 0); \ 54 | } 55 | 56 | #define SWAPINIT(a, es) swaptype = ((char *)a - (char *)0) % sizeof(long) || \ 57 | es % sizeof(long) ? 2 : es == sizeof(long)? 0 : 1; 58 | 59 | static inline void 60 | swapfunc(char *a, char *b, int n, int swaptype) 61 | { 62 | if(swaptype <= 1) 63 | swapcode(long, a, b, n) 64 | else 65 | swapcode(char, a, b, n) 66 | } 67 | 68 | #define swap(a, b) \ 69 | if (swaptype == 0) { \ 70 | long t = *(long *)(a); \ 71 | *(long *)(a) = *(long *)(b); \ 72 | *(long *)(b) = t; \ 73 | } else \ 74 | swapfunc(a, b, es, swaptype) 75 | 76 | #define vecswap(a, b, n) if ((n) > 0) swapfunc(a, b, n, swaptype) 77 | 78 | #define CMP(t, x, y) (cmp((t), (x), (y))) 79 | 80 | static inline char * 81 | med3(char *a, char *b, char *c, cmp_t *cmp, void *thunk) 82 | { 83 | return CMP(thunk, a, b) < 0 ? 84 | (CMP(thunk, b, c) < 0 ? b : (CMP(thunk, a, c) < 0 ? c : a )) 85 | :(CMP(thunk, b, c) > 0 ? b : (CMP(thunk, a, c) < 0 ? a : c )); 86 | } 87 | 88 | void qsort_r(void *a, size_t n, size_t es, void *thunk, cmp_t *cmp) 89 | { 90 | char *pa, *pb, *pc, *pd, *pl, *pm, *pn; 91 | size_t d, r; 92 | int cmp_result; 93 | int swaptype, swap_cnt; 94 | 95 | loop: SWAPINIT(a, es); 96 | swap_cnt = 0; 97 | if (n < 7) { 98 | for (pm = (char *)a + es; pm < (char *)a + n * es; pm += es) 99 | for (pl = pm; 100 | pl > (char *)a && CMP(thunk, pl - es, pl) > 0; 101 | pl -= es) 102 | swap(pl, pl - es); 103 | return; 104 | } 105 | pm = (char *)a + (n / 2) * es; 106 | if (n > 7) { 107 | pl = a; 108 | pn = (char *)a + (n - 1) * es; 109 | if (n > 40) { 110 | d = (n / 8) * es; 111 | pl = med3(pl, pl + d, pl + 2 * d, cmp, thunk); 112 | pm = med3(pm - d, pm, pm + d, cmp, thunk); 113 | pn = med3(pn - 2 * d, pn - d, pn, cmp, thunk); 114 | } 115 | pm = med3(pl, pm, pn, cmp, thunk); 116 | } 117 | swap(a, pm); 118 | pa = pb = (char *)a + es; 119 | 120 | pc = pd = (char *)a + (n - 1) * es; 121 | for (;;) { 122 | while (pb <= pc && (cmp_result = CMP(thunk, pb, a)) <= 0) { 123 | if (cmp_result == 0) { 124 | swap_cnt = 1; 125 | swap(pa, pb); 126 | pa += es; 127 | } 128 | pb += es; 129 | } 130 | while (pb <= pc && (cmp_result = CMP(thunk, pc, a)) >= 0) { 131 | if (cmp_result == 0) { 132 | swap_cnt = 1; 133 | swap(pc, pd); 134 | pd -= es; 135 | } 136 | pc -= es; 137 | } 138 | if (pb > pc) 139 | break; 140 | swap(pb, pc); 141 | swap_cnt = 1; 142 | pb += es; 143 | pc -= es; 144 | } 145 | if (swap_cnt == 0) { /* Switch to insertion sort */ 146 | for (pm = (char *)a + es; pm < (char *)a + n * es; pm += es) 147 | for (pl = pm; 148 | pl > (char *)a && CMP(thunk, pl - es, pl) > 0; 149 | pl -= es) 150 | swap(pl, pl - es); 151 | return; 152 | } 153 | 154 | pn = (char *)a + n * es; 155 | r = min(pa - (char *)a, pb - pa); 156 | vecswap(a, pb - r, r); 157 | r = min(pd - pc, pn - pd - es); 158 | vecswap(pb, pn - r, r); 159 | if ((r = pb - pa) > es) 160 | qsort_r(a, r / es, es, thunk, cmp); 161 | if ((r = pd - pc) > es) { 162 | /* Iterate rather than recurse to save stack space */ 163 | a = pn - r; 164 | n = r / es; 165 | goto loop; 166 | } 167 | } 168 | 169 | -------------------------------------------------------------------------------- /qsortex.c: -------------------------------------------------------------------------------- 1 | /*---------------------------------------------------------------------------*/ 2 | /* qsort() - perform a quicksort on an array */ 3 | /*---------------------------------------------------------------------------*/ 4 | #include 5 | #include 6 | #include 7 | #include "containers.h" 8 | 9 | 10 | /* 11 | // qsort.c 12 | // 13 | // Quick sort 14 | // 15 | // Copyright (C) 2002 Michael Ringgaard. All rights reserved. 16 | // 17 | // Redistribution and use in source and binary forms, with or without 18 | // modification, are permitted provided that the following conditions 19 | // are met: 20 | // 21 | // 1. Redistributions of source code must retain the above copyright 22 | // notice, this list of conditions and the following disclaimer. 23 | // 2. Redistributions in binary form must reproduce the above copyright 24 | // notice, this list of conditions and the following disclaimer in the 25 | // documentation and/or other materials provided with the distribution. 26 | // 3. Neither the name of the project nor the names of its contributors 27 | // may be used to endorse or promote products derived from this software 28 | // without specific prior written permission. 29 | // 30 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 31 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 32 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 33 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 34 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 35 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 36 | // OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 37 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 38 | // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 39 | // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 40 | // SUCH DAMAGE. 41 | */ 42 | 43 | #define CUTOFF 8 44 | 45 | static void shortsort(char *lo, char *hi, size_t width, int (*comp)(const void *, const void *,CompareInfo *ExtraArgs),CompareInfo *ExtraARgs); 46 | static void swap(char *p, char *q, size_t width); 47 | 48 | void qsortEx(void *base, size_t num, size_t width, CompareFunction comp, CompareInfo *ExtraArgs) 49 | { 50 | char *lo, *hi; 51 | char *mid; 52 | char *loguy, *higuy; 53 | size_t size; 54 | char *lostk[30], *histk[30]; 55 | int stkptr; 56 | 57 | if (num < 2 || width == 0) return; 58 | stkptr = 0; 59 | 60 | lo = base; 61 | hi = (char *) base + width * (num - 1); 62 | 63 | recurse: 64 | size = (hi - lo) / width + 1; 65 | 66 | if (size <= CUTOFF) 67 | { 68 | shortsort(lo, hi, width, comp,ExtraArgs); 69 | } 70 | else 71 | { 72 | mid = lo + (size / 2) * width; 73 | swap(mid, lo, width); 74 | 75 | loguy = lo; 76 | higuy = hi + width; 77 | 78 | for (;;) { 79 | // Changed <= to < and >= to > according to the advise of "pete" of comp.lang.c. 80 | do { loguy += width; } while (loguy <= hi && comp(loguy, lo,ExtraArgs) < 0); 81 | do { higuy -= width; } while (higuy > lo && comp(higuy, lo,ExtraArgs) > 0); 82 | if (higuy < loguy) break; 83 | swap(loguy, higuy, width); 84 | } 85 | 86 | swap(lo, higuy, width); 87 | 88 | if (higuy - 1 - lo >= hi - loguy) 89 | { 90 | if (lo + width < higuy) 91 | { 92 | lostk[stkptr] = lo; 93 | histk[stkptr] = higuy - width; 94 | ++stkptr; 95 | } 96 | 97 | if (loguy < hi) 98 | { 99 | lo = loguy; 100 | goto recurse; 101 | } 102 | } 103 | else 104 | { 105 | if (loguy < hi) 106 | { 107 | lostk[stkptr] = loguy; 108 | histk[stkptr] = hi; 109 | ++stkptr; 110 | } 111 | 112 | if (lo + width < higuy) 113 | { 114 | hi = higuy - width; 115 | goto recurse; 116 | } 117 | } 118 | } 119 | 120 | --stkptr; 121 | if (stkptr >= 0) 122 | { 123 | lo = lostk[stkptr]; 124 | hi = histk[stkptr]; 125 | goto recurse; 126 | } 127 | else 128 | return; 129 | } 130 | 131 | static void shortsort(char *lo, char *hi, size_t width, CompareFunction comp,CompareInfo *ExtraArgs) 132 | { 133 | char *p, *max; 134 | 135 | while (hi > lo) 136 | { 137 | max = lo; 138 | for (p = lo+width; p <= hi; p += width) if (comp(p, max,ExtraArgs) > 0) max = p; 139 | swap(max, hi, width); 140 | hi -= width; 141 | } 142 | } 143 | 144 | static void swap(char *a, char *b, size_t width) 145 | { 146 | char tmp; 147 | 148 | if (a != b) 149 | { 150 | while (width--) 151 | { 152 | tmp = *a; 153 | *a++ = *b; 154 | *b++ = tmp; 155 | } 156 | } 157 | } 158 | 159 | 160 | -------------------------------------------------------------------------------- /queue.c: -------------------------------------------------------------------------------- 1 | #include "containers.h" 2 | /* ------------------------------------------------------------------- 3 | * QUEUES 4 | * -------------------------------------------------------------------*/ 5 | typedef struct _Queue { 6 | QueueInterface *VTable; 7 | List *Items; 8 | } _Queue; 9 | 10 | static size_t QSize(Queue *Q) 11 | { 12 | return iList.Size(Q->Items); 13 | } 14 | 15 | static size_t Sizeof(Queue *q) 16 | { 17 | if (q == NULL) return sizeof(Queue); 18 | return sizeof(*q) + iList.Sizeof(q->Items); 19 | } 20 | 21 | static int Finalize(Queue *Q) 22 | { 23 | const ContainerAllocator *allocator = iList.GetAllocator(Q->Items); 24 | iList.Finalize(Q->Items); 25 | allocator->free(Q); 26 | return 1; 27 | } 28 | 29 | static int QClear(Queue *Q) 30 | { 31 | return iList.Clear(Q->Items); 32 | } 33 | 34 | 35 | static int Dequeue(Queue *Q,void *result) 36 | { 37 | return iList.PopFront(Q->Items,result); 38 | } 39 | 40 | static int Enqueue(Queue *Q,void *newval) 41 | { 42 | return iList.Add(Q->Items,newval); 43 | } 44 | 45 | 46 | static Queue *CreateWithAllocator(size_t ElementSize,ContainerAllocator *allocator) 47 | { 48 | Queue *result = allocator->malloc(sizeof(Queue)); 49 | 50 | if (result == NULL) 51 | return NULL; 52 | result->Items = iList.CreateWithAllocator(ElementSize,allocator); 53 | if (result->Items == NULL) { 54 | allocator->free(result); 55 | return NULL; 56 | } 57 | result->VTable = &iQueue; 58 | return result; 59 | } 60 | 61 | static Queue *Create(size_t ElementSize) 62 | { 63 | return CreateWithAllocator(ElementSize,CurrentAllocator); 64 | } 65 | static int Front(Queue *Q,void *result) 66 | { 67 | size_t idx; 68 | if (Q == NULL) { 69 | iError.RaiseError("iQueue.Front",CONTAINER_ERROR_BADARG); 70 | return CONTAINER_ERROR_BADARG; 71 | } 72 | idx = iList.Size(Q->Items); 73 | if (idx == 0) 74 | return 0; 75 | return iList.CopyElement(Q->Items,0,result); 76 | } 77 | 78 | static int Back(Queue *Q,void *result) 79 | { 80 | size_t idx; 81 | if (Q == NULL) { 82 | iError.RaiseError("iQueue.Front",CONTAINER_ERROR_BADARG); 83 | return CONTAINER_ERROR_BADARG; 84 | } 85 | idx = iList.Size(Q->Items); 86 | if (idx == 0) 87 | return 0; 88 | return iList.CopyElement(Q->Items,idx-1,result); 89 | } 90 | 91 | static List *GetData(Queue *q) 92 | { 93 | if (q == NULL) { 94 | iError.RaiseError("iQueue.GetData",CONTAINER_ERROR_BADARG); 95 | return NULL; 96 | } 97 | return q->Items; 98 | } 99 | 100 | 101 | QueueInterface iQueue = { 102 | Create, 103 | CreateWithAllocator, 104 | QSize, 105 | Sizeof, 106 | Enqueue, 107 | Dequeue, 108 | QClear, 109 | Finalize, 110 | Front, 111 | Back, 112 | GetData, 113 | }; 114 | -------------------------------------------------------------------------------- /sequential.c: -------------------------------------------------------------------------------- 1 | #include "containers.h" 2 | #include "ccl_internal.h" 3 | 4 | struct SequentialContainer { 5 | SequentialContainerInterface *vTable; 6 | size_t Size; 7 | unsigned Flags; 8 | size_t ElementSize; 9 | }; 10 | 11 | static size_t Size(const SequentialContainer *gen) 12 | { 13 | if (gen == NULL) { 14 | iError.RaiseError("iGeneric.Size",CONTAINER_ERROR_BADARG); 15 | return 0; 16 | } 17 | return gen->Size; 18 | } 19 | 20 | static unsigned GetFlags(const SequentialContainer *gen) 21 | { 22 | if (gen == NULL) { 23 | iError.RaiseError("iGneric.GetFlags",CONTAINER_ERROR_BADARG); 24 | return 0; 25 | } 26 | return gen->Flags; 27 | } 28 | 29 | static unsigned SetFlags(SequentialContainer *gen,unsigned newFlags) 30 | { 31 | unsigned result; 32 | if (gen == NULL) { 33 | iError.RaiseError("iGeneric.SetFlags",CONTAINER_ERROR_BADARG); 34 | return 0; 35 | } 36 | result = gen->Flags; 37 | gen->Flags = newFlags; 38 | return result; 39 | } 40 | 41 | static int Clear(SequentialContainer *gen) 42 | { 43 | return gen->vTable->Clear(gen); 44 | } 45 | 46 | static int Contains(const SequentialContainer *gen,const void *value) 47 | { 48 | return gen->vTable->Contains(gen,value); 49 | } 50 | 51 | static int Erase(SequentialContainer *gen,const void *elem) 52 | { 53 | return gen->vTable->Erase(gen,elem); 54 | } 55 | 56 | static int EraseAll(SequentialContainer *gen,const void *elem) 57 | { 58 | return gen->vTable->EraseAll(gen,elem); 59 | } 60 | 61 | static int Finalize(SequentialContainer *gen) 62 | { 63 | return gen->vTable->Finalize(gen); 64 | } 65 | 66 | static void Apply(SequentialContainer *Gen,int (*Applyfn)(void *,void * arg),void *arg) 67 | { 68 | Gen->vTable->Apply(Gen,Applyfn,arg); 69 | } 70 | 71 | static int Equal(const SequentialContainer *Gen1,const SequentialContainer *Gen2) 72 | { 73 | return Gen1->vTable->Equal(Gen1,Gen2); 74 | } 75 | 76 | static SequentialContainer *Copy(const SequentialContainer *src) 77 | { 78 | return src->vTable->Copy(src); 79 | } 80 | 81 | static ErrorFunction SetErrorFunction(SequentialContainer *Gen,ErrorFunction fn) 82 | { 83 | return Gen->vTable->SetErrorFunction(Gen,fn); 84 | } 85 | 86 | static size_t Sizeof(const SequentialContainer *gen) 87 | { 88 | return gen->vTable->Sizeof(gen); 89 | } 90 | 91 | static Iterator *NewIterator(SequentialContainer *gen) 92 | { 93 | return gen->vTable->NewIterator(gen); 94 | } 95 | static int InitIterator(SequentialContainer *gen,void *buf) 96 | { 97 | return gen->vTable->InitIterator(gen,buf); 98 | } 99 | 100 | static int deleteIterator(Iterator *git) 101 | { 102 | SequentialIterator *GenIt = (SequentialIterator *)git; 103 | SequentialContainer *gen = GenIt->Gen; 104 | return gen->vTable->deleteIterator(git); 105 | } 106 | 107 | static size_t SizeofIterator(const SequentialContainer *git) 108 | { 109 | SequentialIterator *GenIt = (SequentialIterator *)git; 110 | SequentialContainer *gen = GenIt->Gen; 111 | return gen->vTable->SizeofIterator(git); 112 | } 113 | 114 | static int Save(const SequentialContainer *gen, FILE *stream,SaveFunction saveFn,void *arg) 115 | { 116 | return gen->vTable->Save(gen,stream,saveFn,arg); 117 | } 118 | /*-----------------------------------------------------------------------------------*/ 119 | /* */ 120 | /* Sequential containers */ 121 | /* */ 122 | /*-----------------------------------------------------------------------------------*/ 123 | 124 | static int Add(SequentialContainer *sc, const void *Element) 125 | { 126 | return sc->vTable->Add(sc,Element); 127 | } 128 | 129 | static void *GetElement(const SequentialContainer *sc,size_t idx) 130 | { 131 | return sc->vTable->GetElement(sc,idx); 132 | } 133 | 134 | static int Push(SequentialContainer *gen,void *Element) 135 | { 136 | return gen->vTable->Push(gen,Element); 137 | } 138 | 139 | static int Pop(SequentialContainer *g,void *Element) 140 | { 141 | return g->vTable->Pop(g,Element); 142 | } 143 | 144 | static int InsertAt(SequentialContainer *gen,size_t idx,const void *newval) 145 | { 146 | return gen->vTable->InsertAt(gen,idx,newval); 147 | } 148 | 149 | static int EraseAt(SequentialContainer *g,size_t idx) 150 | { 151 | return g->vTable->EraseAt(g,idx); 152 | } 153 | 154 | static int ReplaceAt(SequentialContainer *s,size_t idx,const void *newelem) 155 | { 156 | return s->vTable->ReplaceAt(s,idx,newelem); 157 | } 158 | 159 | static int IndexOf(const SequentialContainer *g,const void *elemToFind, 160 | void *args,size_t *result) 161 | { 162 | return g->vTable->IndexOf(g,elemToFind,args,result); 163 | } 164 | 165 | 166 | static int Append(SequentialContainer *g1,SequentialContainer *g2) 167 | { 168 | int r; 169 | void *element; 170 | Iterator *it1 = NewIterator((SequentialContainer *) 171 | g2); 172 | for (element = it1->GetFirst(it1); 173 | element != NULL; 174 | element = it1->GetNext(it1)) { 175 | r = Add(g1,element); 176 | if (r <=0) { 177 | return r; 178 | } 179 | 180 | } 181 | return 1; 182 | } 183 | 184 | 185 | SequentialContainerInterface iSequentialContainer = { 186 | Size, 187 | GetFlags, 188 | SetFlags, 189 | Clear, 190 | Contains, 191 | Erase, 192 | EraseAll, 193 | Finalize, 194 | Apply, 195 | Equal, 196 | Copy, 197 | SetErrorFunction, 198 | Sizeof, 199 | NewIterator, 200 | InitIterator, 201 | deleteIterator, 202 | SizeofIterator, 203 | Save, 204 | Add, 205 | GetElement, 206 | Push, 207 | Pop, 208 | InsertAt, 209 | EraseAt, 210 | ReplaceAt, 211 | IndexOf, 212 | Append, 213 | }; 214 | -------------------------------------------------------------------------------- /stdint.h.noc99: -------------------------------------------------------------------------------- 1 | #ifndef __stdint_h__ 2 | #define __stdint_h__ 3 | typedef char int8_t; 4 | typedef unsigned char uint8_t; 5 | #define INT8_C(a) a 6 | #define UINT8_C(a) (a##U) 7 | typedef short int16_t; 8 | typedef unsigned short uint16_t; 9 | #define INT16_C(a) a 10 | #define UINT16_C(a) (a##U) 11 | typedef int int32_t; 12 | #define INT32_C(a) (a) 13 | typedef unsigned int uint32_t; 14 | #define UINT32_C(a) (a##U) 15 | typedef long long int64_t; 16 | #define INT64_C(a) (a##LL) 17 | typedef unsigned long long uint64_t; 18 | #define UINT64_C(a) (a##ULL) 19 | 20 | typedef char int_least8_t; 21 | typedef unsigned char uint_least8_t; 22 | typedef short int_least16_t; 23 | typedef unsigned short uint_least16_t; 24 | typedef int int_least32_t; 25 | typedef unsigned int uint_least32_t; 26 | typedef long long int_least64_t; 27 | typedef unsigned long long uint_least64_t; 28 | 29 | #define INTMAX_C(a) (a##LL) 30 | #define UINTMAX_C(a) (a##ULL) 31 | 32 | typedef char int_fast8_t; 33 | typedef unsigned char uint_fast8_t; 34 | typedef short int_fast16_t; 35 | typedef unsigned short uint_fast16_t; 36 | typedef int int_fast32_t; 37 | typedef unsigned int uint_fast32_t; 38 | typedef long long int_fast64_t; 39 | typedef unsigned long long uint_fast64_t; 40 | 41 | typedef int intptr_t; 42 | typedef unsigned int uintptr_t; 43 | typedef long long intmax_t; 44 | typedef unsigned long long uintmax_t; 45 | 46 | #define INT8_MIN (-128) 47 | #define INT16_MIN (-32768) 48 | #define INT32_MIN (-2147483648) 49 | #define INT64_MIN (-9223372036854775808LL) 50 | 51 | 52 | #define INT8_MAX 127 53 | #define INT16_MAX 32767 54 | #define INT32_MAX 2147483647 55 | #define INT64_MAX 9223372036854775807LL 56 | 57 | #define UINT8_MAX 255 58 | #define UINT16_MAX 65535 59 | #ifndef UINT32_MAX 60 | #define UINT32_MAX 4294967295 61 | #endif 62 | #define UINT64_MAX 18446744073709551615ULL 63 | 64 | #define INT_LEAST8_MIN (-128) 65 | #define INT_LEAST16_MIN (-32768) 66 | #define INT_LEAST32_MIN (-2147483648) 67 | #define INT_LEAST64_MIN (-9223372036854775808LL) 68 | 69 | #define INT_LEAST8_MAX 127 70 | #define INT_LEAST16_MAX 32767 71 | #define INT_LEAST32_MAX 2147483647 72 | #define INT_LEAST64_MAX 9223372036854775807LL 73 | 74 | #define UINT_LEAST8_MAX 255 75 | #define UINT_LEAST16_MAX 65535 76 | #define UINT_LEAST32_MAX 4294967295 77 | #define UINT_LEAST64_MAX 18446744073709551615ULL 78 | 79 | #define INT_FAST8_MIN (-128) 80 | #define INT_FAST16_MIN (-32768) 81 | #define INT_FAST32_MIN (-2147483648) 82 | #define INT_FAST64_MIN (-9223372036854775808LL) 83 | 84 | #define INT_FAST8_MAX 127 85 | #define INT_FAST16_MAX 32767 86 | #define INT_FAST32_MAX 2147483647 87 | #define INT_FAST64_MAX 9223372036854775807LL 88 | 89 | #define UINT_FAST8_MAX 255 90 | #define UINT_FAST16_MAX 65535 91 | #define UINT_FAST32_MAX 4294967295 92 | #define UINT_FAST64_MAX 18446744073709551615LL 93 | 94 | #define INTPTR_MIN INT32_MIN 95 | #define INTPTR_MAX INT32_MAX 96 | #define UINTPTR_MAX UINT32_MAX 97 | 98 | #define INTMAX_MIN INT64_MIN 99 | #define INTMAX_MAX INT64_MAX 100 | #define UINTMAX_MAX UINT64_MAX 101 | 102 | #ifndef SIZE_MAX 103 | #define SIZE_MAX 0xffffffff 104 | #endif 105 | #define PTRDIFF_MIN INT32_MIN 106 | #define PTRDIFF_MAX INT32_MAX 107 | 108 | #ifndef RSIZE_MAX 109 | #define RSIZE_MAX INT32_MAX 110 | #endif 111 | 112 | #endif 113 | -------------------------------------------------------------------------------- /strcollection.c: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------ 2 | Module: wstrcollection.c 3 | Author: jacob 4 | Project: Containers 5 | State: 6 | Creation Date: 7 | Description: Implements the string collection container. 8 | Added fixes from Gerome. Oct. 20 2005 9 | ------------------------------------------------------------------------*/ 10 | #include 11 | #include "containers.h" 12 | #include "ccl_internal.h" 13 | #define CHAR_TYPE char 14 | #define SNPRINTF snprintf 15 | #define STRCMP strcmp 16 | #define STRICMP stricmp 17 | #define STRCPY strcpy 18 | #define STRLEN strlen 19 | #define STRSTR strstr 20 | #define ElementType strCollection 21 | #define iElementType istrCollection 22 | #define STRSTR strstr 23 | #define GETLINE GetLine 24 | #define STRCOMPAREFUNCTION StringCompareFn 25 | #define INTERFACE_TYP strCollectionInterface 26 | #define INTERFACE_OBJECT istrCollection 27 | #define NEWLINE '\n' 28 | 29 | static const guid strCollectionGuid = {0x64bea19b, 0x243b, 0x487a, 30 | {0x9a,0xd6,0xcd,0xfe,0xa9,0x37,0x6e,0x88} 31 | }; 32 | 33 | #include "strcollectiongen.c" 34 | -------------------------------------------------------------------------------- /stringlist.c: -------------------------------------------------------------------------------- 1 | #include "containers.h" 2 | #include "ccl_internal.h" 3 | #undef CHARTYPE 4 | #undef DATA_TYPE 5 | 6 | #define CHARTYPE char 7 | #define STRCPY strcpy 8 | #define STRLEN strlen 9 | #define STRCMP strcmp 10 | #define DATA_TYPE String 11 | static const guid StringListGuid = {0x13327EA7,0x78ED,0x4FD2, 12 | {0x95,0xED,0x1C,0x11,0x0E,0xB9,0x71,0x9C} 13 | }; 14 | 15 | #include "stringlistgen.c" 16 | #undef CHARTYPE 17 | #undef STRCPY 18 | #undef STRLEN 19 | #undef STRCMP 20 | #undef iSTRINGLIST 21 | #undef INTERFACE 22 | #undef LIST_ELEMENT 23 | #undef LIST_TYPE 24 | #undef LIST_TYPE_Iterator 25 | -------------------------------------------------------------------------------- /stringlist.h: -------------------------------------------------------------------------------- 1 | #undef CHARTYPE 2 | #undef DATA_TYPE 3 | #define CHARTYPE char 4 | #define DATA_TYPE String 5 | #include "stringlistgen.h" 6 | -------------------------------------------------------------------------------- /stringlistgen.h: -------------------------------------------------------------------------------- 1 | #ifndef __containers_h__ 2 | #include "containers.h" 3 | #endif 4 | #undef CONCAT 5 | #undef CONCAT3 6 | #undef EVAL 7 | #undef iSTRINGLIST 8 | #undef INTERFACE 9 | #undef LIST_ELEMENT 10 | #undef LIST_TYPE 11 | #undef ITERATOR 12 | #undef INTERFACE_STRUCT_INTERNAL_NAME 13 | #undef LIST_STRUCT_INTERNAL_NAME 14 | 15 | #define CONCAT(x,y) x ## y 16 | #define CONCAT3_(a,b,c) a##b##c 17 | #define CONCAT3(a,b,c) CONCAT3_(a,b,c) 18 | #define EVAL(t) t 19 | #define iSTRINGLIST(t) CONCAT3(i,t,Interface) 20 | #define INTERFACE(t) CONCAT(t,ListInterface) 21 | #define LIST_ELEMENT(t) CONCAT(t,ListElement) 22 | #define LIST_TYPE(t) CONCAT(t,List) 23 | #define ITERATOR(t) CONCAT(t,ListIterator) 24 | #define INTERFACE_STRUCT_INTERNAL_NAME(a) CONCAT3(__,EVAL(a),ListInterface) 25 | #define LIST_STRUCT_INTERNAL_NAME(a) CONCAT3(__,EVAL(a),List) 26 | 27 | #ifdef NO_C99 28 | /* No flexible arrays */ 29 | #define MINIMUM_ARRAY_INDEX 1 30 | #else 31 | /* Use C99 features */ 32 | #define MINIMUM_ARRAY_INDEX 33 | #endif 34 | 35 | /*----------------------------------------------------------------------------*/ 36 | /* Definition of the stringlist and stringlist element type */ 37 | /*----------------------------------------------------------------------------*/ 38 | typedef struct LIST_ELEMENT(DATA_TYPE) { 39 | struct LIST_ELEMENT(DATA_TYPE) *Next; 40 | CHARTYPE Data[MINIMUM_ARRAY_INDEX]; 41 | } LIST_ELEMENT(DATA_TYPE); 42 | 43 | typedef struct INTERFACE_STRUCT_INTERNAL_NAME(DATA_TYPE) INTERFACE(DATA_TYPE); 44 | typedef struct LIST_STRUCT_INTERNAL_NAME(DATA_TYPE) { 45 | INTERFACE(DATA_TYPE) *VTable; /* Methods table */ 46 | size_t count; /* in elements units */ 47 | unsigned Flags; 48 | unsigned timestamp; /* Changed at each modification */ 49 | size_t ElementSize; /* Size (in bytes) of each element */ 50 | LIST_ELEMENT(DATA_TYPE) *Last; /* The last item */ 51 | LIST_ELEMENT(DATA_TYPE) *First; /* The contents of the list start here */ 52 | CompareFunction Compare; /* Element comparison function */ 53 | ErrorFunction RaiseError; /* Error function */ 54 | ContainerHeap *Heap; 55 | const ContainerAllocator *Allocator; 56 | DestructorFunction DestructorFn; 57 | } LIST_TYPE(DATA_TYPE); 58 | 59 | struct ITERATOR(DATA_TYPE) { 60 | Iterator it; 61 | LIST_TYPE(DATA_TYPE) *L; 62 | size_t index; 63 | LIST_ELEMENT(DATA_TYPE) *Current; 64 | LIST_ELEMENT(DATA_TYPE) *Previous; 65 | unsigned timestamp; 66 | CHARTYPE *ElementBuffer; 67 | }; 68 | 69 | struct INTERFACE_STRUCT_INTERNAL_NAME(DATA_TYPE) { 70 | size_t (*Size)(const LIST_TYPE(DATA_TYPE) *L); /* Returns the number of elements stored */ 71 | unsigned (*GetFlags)(const LIST_TYPE(DATA_TYPE) *L); /* Gets the flags */ 72 | unsigned (*SetFlags)(LIST_TYPE(DATA_TYPE) *L,unsigned flags); /* Sets the flags */ 73 | int (*Clear)(LIST_TYPE(DATA_TYPE) *L); /* Clears all elements */ 74 | int (*Contains)(const LIST_TYPE(DATA_TYPE) *L,const CHARTYPE *element); /* Searches an element */ 75 | int (*Erase)(LIST_TYPE(DATA_TYPE) *L,CHARTYPE *); /* erases the given data if found */ 76 | /* Frees the memory used by the collection and destroys the list */ 77 | int (*Finalize)(LIST_TYPE(DATA_TYPE) *L); 78 | /* Call a callback function with each element of the list and an extra argument */ 79 | int (*Apply)(LIST_TYPE(DATA_TYPE) *L,int(Applyfn)(CHARTYPE *,void *),void *arg); 80 | int (*Equal)(LIST_TYPE(DATA_TYPE) *l1,LIST_TYPE(DATA_TYPE) *l2); /* Compares two lists (Shallow comparison) */ 81 | LIST_TYPE(DATA_TYPE) *(*Copy)(const LIST_TYPE(DATA_TYPE) *L); /* Copies all items into a new list */ 82 | ErrorFunction (*SetErrorFunction)(LIST_TYPE(DATA_TYPE) *L,ErrorFunction); /* Set/unset the error function */ 83 | size_t (*Sizeof)(LIST_TYPE(DATA_TYPE) *l); 84 | Iterator *(*NewIterator)(LIST_TYPE(DATA_TYPE) *L); 85 | int (*deleteIterator)(Iterator *); 86 | size_t (*SizeofIterator)(LIST_TYPE(DATA_TYPE) *l); 87 | int (*Save)(LIST_TYPE(DATA_TYPE) *L,FILE *stream, SaveFunction saveFn,void *arg); 88 | LIST_TYPE(DATA_TYPE) *(*Load)(FILE *stream, ReadFunction loadFn,void *arg); 89 | size_t (*GetElementSize)(LIST_TYPE(DATA_TYPE) *l); 90 | /* -------------------------------------------This is the Sequential container part */ 91 | int (*Add)(LIST_TYPE(DATA_TYPE) *L,CHARTYPE *newval); /* Adds element at end */ 92 | /* Returns the data at the given position */ 93 | CHARTYPE *(*GetElement)(LIST_TYPE(DATA_TYPE) *L,size_t idx); 94 | /* Pushes an element, using the collection as a stack */ 95 | int (*PushFront)(LIST_TYPE(DATA_TYPE) *L,CHARTYPE *str); 96 | /* Pops the first element the list */ 97 | int (*PopFront)(LIST_TYPE(DATA_TYPE) *L,CHARTYPE *result); 98 | /* Inserts a value at the given position */ 99 | int (*InsertAt)(LIST_TYPE(DATA_TYPE) *L,size_t idx,CHARTYPE *newval); 100 | int (*EraseAt)(LIST_TYPE(DATA_TYPE) *L,size_t idx); 101 | /* Replaces the element at the given position with a new one */ 102 | int (*ReplaceAt)(LIST_TYPE(DATA_TYPE) *L,size_t idx,CHARTYPE *newval); 103 | /*Returns the index of the given data or -1 if not found */ 104 | int (*IndexOf)(LIST_TYPE(DATA_TYPE) *L,CHARTYPE *SearchedElement,void *ExtraArgs,size_t *result); 105 | /* -------------------------------------------This is the list container part */ 106 | int (*InsertIn)(LIST_TYPE(DATA_TYPE) *l, size_t idx,LIST_TYPE(DATA_TYPE) *newData); 107 | int (*CopyElement)(LIST_TYPE(DATA_TYPE) *list,size_t idx,CHARTYPE *OutBuffer); 108 | /*erases the string at the indicated position */ 109 | int (*EraseRange)(LIST_TYPE(DATA_TYPE) *L,size_t start,size_t end); 110 | /* Sorts the list in place */ 111 | int (*Sort)(LIST_TYPE(DATA_TYPE) *l); 112 | /* Reverses the list */ 113 | int (*Reverse)(LIST_TYPE(DATA_TYPE) *l); 114 | /* Gets an element range from the list */ 115 | LIST_TYPE(DATA_TYPE) *(*GetRange)(LIST_TYPE(DATA_TYPE) *l,size_t start,size_t end); 116 | /* Add a list at the end of another */ 117 | int (*Append)(LIST_TYPE(DATA_TYPE) *l1,LIST_TYPE(DATA_TYPE) *l2); 118 | /* Set the comparison function */ 119 | CompareFunction (*SetCompareFunction)(LIST_TYPE(DATA_TYPE) *l,CompareFunction fn); 120 | CompareFunction Compare; 121 | int (*UseHeap)(LIST_TYPE(DATA_TYPE) *L, ContainerAllocator *m); 122 | int (*AddRange)(LIST_TYPE(DATA_TYPE) *L, size_t n,CHARTYPE **data); 123 | LIST_TYPE(DATA_TYPE) *(*Create)(void); 124 | LIST_TYPE(DATA_TYPE) *(*CreateWithAllocator)(const ContainerAllocator *allocator); 125 | LIST_TYPE(DATA_TYPE) *(*Init)(LIST_TYPE(DATA_TYPE) *); 126 | LIST_TYPE(DATA_TYPE) *(*InitWithAllocator)(LIST_TYPE(DATA_TYPE) *a,ContainerAllocator *allocator); 127 | LIST_TYPE(DATA_TYPE) *(*SetAllocator)(LIST_TYPE(DATA_TYPE) *l, ContainerAllocator *allocator); 128 | int (*InitIterator)(LIST_TYPE(DATA_TYPE) *list,void *storage); 129 | const ContainerAllocator *(*GetAllocator)(LIST_TYPE(DATA_TYPE) *list); 130 | DestructorFunction (*SetDestructor)(LIST_TYPE(DATA_TYPE) *v,DestructorFunction fn); 131 | LIST_TYPE(DATA_TYPE) *(*InitializeWith)(size_t n,CHARTYPE **data); 132 | CHARTYPE *(*Back)(const LIST_TYPE(DATA_TYPE) *l); 133 | CHARTYPE *(*Front)(const LIST_TYPE(DATA_TYPE) *l); 134 | int (*Select)(LIST_TYPE(DATA_TYPE) *src,const Mask *m); 135 | LIST_TYPE(DATA_TYPE) *(*SelectCopy)(const LIST_TYPE(DATA_TYPE) *src, const Mask *m); 136 | LIST_ELEMENT(DATA_TYPE) *(*FirstElement)(LIST_TYPE(DATA_TYPE) *l); 137 | LIST_ELEMENT(DATA_TYPE) *(*LastElement)(LIST_TYPE(DATA_TYPE) *l); 138 | LIST_ELEMENT(DATA_TYPE) *(*NextElement)(LIST_ELEMENT(DATA_TYPE) *le); 139 | void *(*ElementData)(LIST_ELEMENT(DATA_TYPE) *le); 140 | int (*SetElementData)(LIST_TYPE(DATA_TYPE) *l, LIST_ELEMENT(DATA_TYPE) **pple,const CHARTYPE *data); 141 | void *(*Advance)(LIST_ELEMENT(DATA_TYPE) **p); 142 | LIST_ELEMENT(DATA_TYPE) *(*Skip)(LIST_ELEMENT(DATA_TYPE) *l,size_t n); 143 | LIST_TYPE(DATA_TYPE) *(*SplitAfter)(LIST_TYPE(DATA_TYPE) *l, LIST_ELEMENT(DATA_TYPE) *pt); 144 | }; 145 | 146 | extern INTERFACE(DATA_TYPE) iSTRINGLIST(DATA_TYPE); 147 | 148 | -------------------------------------------------------------------------------- /test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | static void ABORT(char *file,int line) 4 | { 5 | fprintf(stderr,"*****\n\nABORT\nFile %s Line %d\n**********\n\n",file,line); 6 | abort(); 7 | } 8 | #define Abort() ABORT(__FILE__,__LINE__) 9 | static void PrintList(List *l) 10 | { 11 | Iterator *it = iList.NewIterator(l); 12 | int *pi; 13 | 14 | for (pi = it->GetFirst(it); pi != NULL; pi = it->GetNext(it)) { 15 | printf("%d ",*pi); 16 | } 17 | printf("\n"); 18 | } 19 | 20 | static int testRemoveRange(void) 21 | { 22 | List *l1; 23 | int table[] = {1,2,3,4,5,6,7,8,9,10}; 24 | 25 | l1 = iList.InitializeWith(sizeof(int),10,table); 26 | iList.Copy(l1); 27 | printf("Original list:\n"); 28 | PrintList(l1); 29 | printf("Removing element 2 to 5\n"); 30 | iList.RemoveRange(l1,2,5); 31 | PrintList(l1); 32 | return 1; 33 | } 34 | static void testList(void) 35 | { 36 | FILE *outFile; 37 | List *l = iList.Create(sizeof(double)),*l1,*l2; 38 | double d,sum; 39 | const double *pd; 40 | size_t isum=0,msum=0,i; 41 | 42 | testRemoveRange(); 43 | for (i=0; i<1000;i++) { 44 | d = i; 45 | isum += i; 46 | iList.Add(l,(void *)&d); 47 | } 48 | if (iList.Size(l) != 1000) { 49 | Abort(); 50 | } 51 | sum = 0.0; 52 | for (i=0; i<1000;i++) { 53 | pd = iList.GetElement(l,i); 54 | sum += *pd; 55 | } 56 | if (sum != isum) 57 | Abort(); 58 | sum=0; 59 | for (i=0; i< 500;i++) { 60 | iList.PopFront(l,&d); 61 | msum += i; 62 | sum += d; 63 | 64 | } 65 | if (msum != sum) 66 | Abort(); 67 | if ( iList.Size(l) != 500) { 68 | Abort(); 69 | } 70 | l1 = iList.GetRange(l,0,500); 71 | if (!iList.Equal(l,l1)) 72 | Abort(); 73 | l2 = iList.Copy(l); 74 | if (!iList.Equal(l2,l1)) 75 | Abort(); 76 | for (i=0; i0) { 100 | iList.PopFront(l,&d); 101 | i--; 102 | } 103 | if (iList.Size(l) != 0) 104 | Abort(); 105 | iList.Finalize(l1); 106 | iList.Finalize(l2); 107 | iList.Finalize(l); 108 | } 109 | 110 | 111 | static void PrintVector(Vector *AL) 112 | { 113 | size_t i; 114 | printf("Count %ld, Capacity %ld\n",(long)iVector.Size(AL),(long)iVector.GetCapacity(AL)); 115 | for (i=0; i 285 | static void PrintstrCollection(strCollection *SC){ 286 | size_t i; 287 | printf("Count %d, Capacity %d\n",(int)istrCollection.Size(SC),(int)istrCollection.GetCapacity(SC)); 288 | for (i=0; iGetFirst(it); 368 | pi != NULL; pi = it->GetNext(it)) { 369 | sum += *pi; 370 | } 371 | iDictionary.deleteIterator(it); 372 | if (sum != 3) 373 | Abort(); 374 | r=iDictionary.Erase(d,"long data"); 375 | if (r != CONTAINER_ERROR_NOTFOUND) 376 | Abort(); 377 | count = iDictionary.Size(d); 378 | if (count != 2) 379 | Abort(); 380 | iDictionary.Erase(d,"One"); 381 | count = iDictionary.Size(d); 382 | if (count != 1) 383 | Abort(); 384 | iDictionary.Finalize(d); 385 | return 0; 386 | } 387 | 388 | 389 | static int compareDoubles(const void *d1,const void *d2,CompareInfo *arg) 390 | { 391 | double a = *(double *)d1; 392 | double b = *(double *)d2; 393 | if (a < b) 394 | return -1; 395 | else if (a > b) 396 | return 1; 397 | return 0; 398 | } 399 | 400 | static int printDoubleTree(const void *data,void *arg) 401 | { 402 | FILE *f = (FILE *)arg; 403 | fprintf(f,"%g ",*(double *)data); 404 | return 0; 405 | } 406 | #undef MAX_IT 407 | #define MAX_IT 10 408 | static void testBinarySearchTree(void) 409 | { 410 | BinarySearchTree *tree = iBinarySearchTree.Create(sizeof(double)); 411 | BinarySearchTree *tree1 = iBinarySearchTree.Create(sizeof(double)); 412 | double d = 1.0; 413 | size_t i; 414 | 415 | iBinarySearchTree.SetCompareFunction(tree,compareDoubles); 416 | for (i=0; iVTable->Finalize(rb);*/ 539 | return errors; 540 | #else 541 | 542 | #endif 543 | } 544 | -------------------------------------------------------------------------------- /valarray.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * ValArraySize_t * 3 | ****************************************************************************/ 4 | #undef ElementType 5 | #undef ValArrayInterface 6 | #undef ElementType 7 | #undef ValArray 8 | #undef _ValArray 9 | #define _ValArray _ValArraySize_t 10 | #define ElementType size_t 11 | #define ValArrayInterface ValArraySize_tInterface 12 | #define ValArray ValArraySize_t 13 | #define __IS_UNSIGNED__ 14 | #define __IS_INTEGER__ 15 | #include "valarraygen.h" 16 | #undef __IS_UNSIGNED__ 17 | #undef __IS_INTEGER__ 18 | extern ValArraySize_tInterface iValArraySize_t; 19 | 20 | /**************************************************************************** 21 | * ValArrayShort * 22 | ****************************************************************************/ 23 | #undef ElementType 24 | #undef ValArrayInterface 25 | #undef ElementType 26 | #undef ValArray 27 | #undef _ValArray 28 | #define _ValArray _ValArrayShort 29 | #define ElementType short 30 | #define ValArrayInterface ValArrayShortInterface 31 | #define ValArray ValArrayShort 32 | #define __IS_INTEGER__ 33 | #include "valarraygen.h" 34 | #undef __IS_INTEGER__ 35 | extern ValArrayInterface iValArrayShort; 36 | 37 | /**************************************************************************** 38 | * ValArrayInt * 39 | ****************************************************************************/ 40 | #undef ElementType 41 | #undef ValArrayInterface 42 | #undef ElementType 43 | #undef ValArray 44 | #undef _ValArray 45 | #define _ValArray _ValArrayInt 46 | #define ElementType int 47 | #define ValArrayInterface ValArrayIntInterface 48 | #define ValArray ValArrayInt 49 | #define __IS_INTEGER__ 50 | #include "valarraygen.h" 51 | #undef __IS_INTEGER__ 52 | extern ValArrayInterface iValArrayInt; 53 | 54 | /**************************************************************************** 55 | * ValArrayLong * 56 | ****************************************************************************/ 57 | #undef ElementType 58 | #undef ValArrayInterface 59 | #undef ElementType 60 | #undef ValArray 61 | #undef _ValArray 62 | #define _ValArray _ValArrayLong 63 | #define ElementType long 64 | #define ValArrayInterface ValArrayLongInterface 65 | #define ValArray ValArrayLong 66 | #define __IS_INTEGER__ 67 | #include "valarraygen.h" 68 | #undef __IS_INTEGER__ 69 | extern ValArrayInterface iValArrayLong; 70 | 71 | 72 | /**************************************************************************** 73 | * ValArrayDouble * 74 | ****************************************************************************/ 75 | #undef ElementType 76 | #undef ValArrayInterface 77 | #undef ElementType 78 | #undef ValArray 79 | #undef _ValArray 80 | #define _ValArray _ValArrayDouble 81 | #define ElementType double 82 | #define ValArrayInterface ValArrayDoubleInterface 83 | #define ValArray ValArrayDouble 84 | #include "valarraygen.h" 85 | extern ValArrayDoubleInterface iValArrayDouble; 86 | 87 | /**************************************************************************** 88 | * ValArrayLongDouble * 89 | ****************************************************************************/ 90 | #undef ElementType 91 | #undef ValArrayInterface 92 | #undef ElementType 93 | #undef ValArray 94 | #undef _ValArray 95 | #define _ValArray _ValArrayLongDouble 96 | #define ElementType long double 97 | #define ValArrayInterface ValArrayLongDoubleInterface 98 | #define ValArray ValArrayLongDouble 99 | #include "valarraygen.h" 100 | extern ValArrayInterface iValArrayLongDouble; 101 | 102 | /**************************************************************************** 103 | * ValArrayLLong * 104 | ****************************************************************************/ 105 | #undef ElementType 106 | #undef ValArrayInterface 107 | #undef ElementType 108 | #undef ValArray 109 | #undef _ValArray 110 | #define _ValArray _ValArrayLLong 111 | #define ElementType long long 112 | #define ValArrayInterface ValArrayLLongInterface 113 | #define ValArray ValArrayLLong 114 | #define __IS_INTEGER__ 115 | #include "valarraygen.h" 116 | #undef __IS_INTEGER__ 117 | extern ValArrayInterface iValArrayLLong; 118 | 119 | /**************************************************************************** 120 | * ValArrayULLong * 121 | ****************************************************************************/ 122 | #undef ElementType 123 | #undef ValArrayInterface 124 | #undef ElementType 125 | #undef ValArray 126 | #undef _ValArray 127 | #define _ValArray _ValArrayULLong 128 | #define ElementType unsigned long long 129 | #define ValArrayInterface ValArrayULLongInterface 130 | #define ValArray ValArrayULLong 131 | #define __IS_INTEGER__ 132 | #define __IS_UNSIGNED__ 133 | #include "valarraygen.h" 134 | #undef __IS_INTEGER__ 135 | #undef __IS_UNSIGNED__ 136 | extern ValArrayInterface iValArrayULLong; 137 | 138 | 139 | /**************************************************************************** 140 | * ValArrayFloat * 141 | ****************************************************************************/ 142 | #undef ElementType 143 | #undef ValArrayInterface 144 | #undef ElementType 145 | #undef ValArray 146 | #undef _ValArray 147 | #define _ValArray _ValArrayFloat 148 | #define ElementType float 149 | #define ValArrayInterface ValArrayFloatInterface 150 | #define ValArray ValArrayFloat 151 | #include "valarraygen.h" 152 | extern ValArrayInterface iValArrayFloat; 153 | 154 | 155 | /**************************************************************************** 156 | * ValArrayUInt * 157 | ****************************************************************************/ 158 | #undef ElementType 159 | #undef ValArrayInterface 160 | #undef ElementType 161 | #undef ValArray 162 | #undef _ValArray 163 | #define _ValArray _ValArrayUInt 164 | #define ElementType unsigned 165 | #define ValArrayInterface ValArrayUIntInterface 166 | #define ValArray ValArrayUInt 167 | #define __IS_UNSIGNED__ 168 | #define __IS_INTEGER__ 169 | #include "valarraygen.h" 170 | #undef __IS_UNSIGNED__ 171 | #undef __IS_INTEGER__ 172 | extern ValArrayInterface iValArrayUInt; 173 | 174 | 175 | #undef ElementType 176 | #undef ValArrayInterface 177 | #undef ElementType 178 | #undef ValArray 179 | #undef _ValArray 180 | 181 | -------------------------------------------------------------------------------- /valarraydouble.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "containers.h" 3 | #include "ccl_internal.h" 4 | /**************************************************************************** 5 | * ValArrayDouble * 6 | ****************************************************************************/ 7 | #undef ElementType 8 | #undef ValArrayInterface 9 | #undef ElementType 10 | #undef ValArray 11 | #undef tagValArray 12 | #undef _ValArray 13 | #define _ValArray _ValArrayDouble 14 | #define tagValArray tagValArrayDoubleInterface 15 | #define ElementType double 16 | #define ValArrayInterface ValArrayDoubleInterface 17 | #define ValArray ValArrayDouble 18 | #define iValArrayInterface iValArrayDouble 19 | #define MaxElementType DBL_MAX 20 | #define MinElementType DBL_MIN 21 | static const guid ValArrayGuidDouble = {0x39a51a8, 0x2a30, 0x4c88, 22 | {0x9d,0x81,0xf3,0x1f,0x30,0xf4,0x5c,0x85} 23 | }; 24 | #define ValArrayGuid ValArrayGuidDouble 25 | #include "valarraygen.c" 26 | -------------------------------------------------------------------------------- /valarrayfloat.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "containers.h" 3 | #include "ccl_internal.h" 4 | /**************************************************************************** 5 | * ValArrayFloat * 6 | ****************************************************************************/ 7 | #undef ElementType 8 | #undef ValArrayInterface 9 | #undef ElementType 10 | #undef ValArray 11 | #undef tagValArray 12 | #undef _ValArray 13 | #define _ValArray _ValArrayFloat 14 | #define tagValArray tagValArrayFloatInterface 15 | #define ElementType float 16 | #define ValArrayInterface ValArrayFloatInterface 17 | #define ValArray ValArrayFloat 18 | #define iValArrayInterface iValArrayFloat 19 | #define MaxElementType FLT_MAX 20 | #define MinElementType FLT_MIN 21 | static const guid ValArrayGuidFloat = {0xb614486e, 0x61e2, 0x45bf, 22 | {0xb3,0xf5,0x7,0xfc,0xd3,0x55,0x77,0x9} 23 | }; 24 | #define ValArrayGuid ValArrayGuidFloat 25 | #include "valarraygen.c" 26 | -------------------------------------------------------------------------------- /valarraygen.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * ValArrays * 3 | ****************************************************************************/ 4 | typedef struct _ValArray ValArray; 5 | typedef struct { 6 | size_t (*Size)(const ValArray *AL); 7 | unsigned (*GetFlags)(const ValArray *AL); 8 | unsigned (*SetFlags)(ValArray *AL,unsigned flags); 9 | int (*Clear)(ValArray *AL); 10 | int (*Contains)(const ValArray *AL,ElementType data); 11 | int (*Erase)(ValArray *AL,ElementType elem); 12 | int (*Finalize)(ValArray *AL); 13 | int (*Apply)(ValArray *AL,int (*Applyfn)(ElementType element,void * arg),void *arg); 14 | int (*Equal)(const ValArray *first, const ValArray *second); 15 | ValArray *(*Copy)(const ValArray *AL); 16 | ErrorFunction (*SetErrorFunction)(ValArray *AL,ErrorFunction); 17 | size_t (*Sizeof)(const ValArray *AL); 18 | Iterator *(*NewIterator)(ValArray *AL); 19 | int (*InitIterator)(ValArray *AL,void *buf); 20 | int (*deleteIterator)(Iterator *); 21 | size_t (*SizeofIterator)(const ValArray *); 22 | int (*Save)(const ValArray *AL,FILE *stream); 23 | ValArray *(*Load)(FILE *stream); 24 | size_t (*GetElementSize)(const ValArray *AL); 25 | 26 | /* Sequential container specific fields */ 27 | 28 | int (*Add)(ValArray *AL,ElementType newval); 29 | ElementType (*GetElement)(const ValArray *AL,size_t idx); 30 | int (*PushBack)(ValArray *AL,ElementType data); 31 | int (*PopBack)(ValArray *AL,ElementType *result); 32 | int (*InsertAt)(ValArray *AL,size_t idx,ElementType newval); 33 | int (*EraseAt)(ValArray *AL,size_t idx); 34 | int (*ReplaceAt)(ValArray *AL,size_t idx,ElementType newval); 35 | /* NO extra args */ 36 | int (*IndexOf)(ValArray *AL,ElementType data,size_t *result); 37 | 38 | /* ValArray container specific fields */ 39 | 40 | int (*Insert)(ValArray *AL,ElementType); 41 | int (*InsertIn)(ValArray *AL, size_t idx, ValArray *newData); 42 | ValArray *(*IndexIn)(const ValArray *SC,const ValArraySize_t *AL); 43 | size_t (*GetCapacity)(const ValArray *AL); 44 | int (*SetCapacity)(ValArray *AL,size_t newCapacity); 45 | 46 | CompareFunction (*SetCompareFunction)(ValArray *l,CompareFunction fn); 47 | int (*Sort)(ValArray *AL); 48 | ValArray *(*Create)(size_t startsize); 49 | ValArray *(*CreateWithAllocator)(size_t startsize, ContainerAllocator *allocator); 50 | ValArray *(*Init)(ValArray *AL,size_t startsize); 51 | int (*AddRange)(ValArray *AL,size_t n, const ElementType *newvalues); 52 | ValArray *(*GetRange)(const ValArray *AL, size_t start, size_t end); 53 | int (*CopyElement)(const ValArray *AL,size_t idx,ElementType *outbuf); 54 | ElementType *(*CopyTo)(ValArray *AL); 55 | int (*Reverse)(ValArray *AL); 56 | int (*Append)(ValArray *AL1, ValArray *AL2); 57 | int (*Mismatch)(const ValArray *a1,const ValArray *a2,size_t *mismatch); 58 | ContainerAllocator *(*GetAllocator)(const ValArray *AL); 59 | DestructorFunction (*SetDestructor)(ValArray *cb,DestructorFunction fn); 60 | 61 | /* ValArray specific functions */ 62 | 63 | ErrorFunction RaiseError; /* Error function */ 64 | int (*SumTo)(ValArray *left,const ValArray *right); 65 | int (*SubtractFrom)(ValArray *left, const ValArray *right); 66 | int (*MultiplyWith)(ValArray *left, const ValArray *right); 67 | int (*DivideBy)(ValArray *left, const ValArray *right); 68 | int (*SumScalarTo)(ValArray *left,ElementType right); 69 | int (*SubtractScalarFrom)(ValArray *left, ElementType right); 70 | int (*SubtractFromScalar)(ElementType left, ValArray *right); 71 | int (*MultiplyWithScalar)(ValArray *left, ElementType right); 72 | int (*DivideByScalar)(ValArray *left, ElementType right); 73 | int (*DivideScalarBy)(ValArray *left,ElementType right); 74 | Mask *(*CompareEqual)(const ValArray *left,const ValArray *right,Mask *bytearray); 75 | Mask *(*CompareEqualScalar)(const ValArray *left, const ElementType right, Mask *bytearray); 76 | char *(*Compare)(const ValArray *left, const ValArray *right,char *bytearray); 77 | char *(*CompareScalar)(const ValArray *left, const ElementType right,char *bytearray); 78 | 79 | ValArray *(*CreateSequence)(size_t n,ElementType start, ElementType increment); 80 | ValArray *(*InitializeWith)(size_t n, ElementType *data); 81 | int (*Memset)(ValArray *dst,ElementType fillValue,size_t length); 82 | int (*FillSequential)(ValArray *dst,size_t length,ElementType start, ElementType increment); 83 | int (*SetSlice)(ValArray *src,size_t start,size_t length,size_t increment); 84 | int (*ResetSlice)(ValArray *array); 85 | int (*GetSlice)(ValArray *array,size_t *start,size_t *length, size_t *increment); 86 | ElementType (*Max)(const ValArray *src); 87 | ElementType (*Min)(const ValArray *src); 88 | int (*RotateLeft)(ValArray *AL, size_t n); 89 | int (*RotateRight)(ValArray *AL,size_t n); 90 | #ifdef __IS_UNSIGNED__ 91 | int (*Or)(ValArray *left, const ValArray *right); 92 | int (*And)(ValArray *left, const ValArray *right); 93 | int (*Xor)(ValArray *left, const ValArray *right); 94 | int (*Not)(ValArray *left); 95 | int (*BitLeftShift)(ValArray *data,int shift); 96 | int (*BitRightShift)(ValArray *data, const int shift); 97 | int (*OrScalar)(ValArray *left, const ElementType right); 98 | int (*AndScalar)(ValArray *left, const ElementType right); 99 | int (*XorScalar)(ValArray *left, const ElementType right); 100 | #else 101 | int (*Abs)(ValArray *src); /* Abs only defined for float/signed types */ 102 | #endif 103 | #ifdef __IS_INTEGER__ 104 | int (*Mod)(ValArray *left,const ValArray *right); 105 | int (*ModScalar)(ValArray *left,const ElementType right); 106 | #else 107 | Mask *(*FCompare)(const ValArray *left, const ValArray *right, Mask *bytearray,ElementType tolerance); 108 | int (*Inverse)(ValArray *src); 109 | #endif 110 | int (*ForEach)(ValArray *src,ElementType (*ApplyFn)(ElementType)); 111 | ElementType (*Accumulate)(const ValArray *src); 112 | ElementType (*Product)(const ValArray *src); 113 | int (*Fprintf)(const ValArray *src,FILE *out,const char *fmt); 114 | int (*Select)(ValArray *src,const Mask *m); 115 | ValArray *(*SelectCopy)(const ValArray *src,const Mask *m); 116 | ElementType *(*GetData)(const ValArray *src); 117 | ElementType (*Back)(const ValArray *src); 118 | ElementType (*Front)(const ValArray *src); 119 | int (*RemoveRange)(ValArray *src,size_t start,size_t end); 120 | int (*Resize)(ValArray *src, size_t newSize); 121 | } ValArrayInterface; 122 | -------------------------------------------------------------------------------- /valarrayint.c: -------------------------------------------------------------------------------- 1 | #include "containers.h" 2 | #include "ccl_internal.h" 3 | /**************************************************************************** 4 | * ValArrayInt * 5 | ****************************************************************************/ 6 | #undef ElementType 7 | #undef ValArrayInterface 8 | #undef ElementType 9 | #undef ValArray 10 | #undef tagValArray 11 | #undef _ValArray 12 | #define _ValArray _ValArrayInt 13 | #define tagValArray tagValArrayIntInterface 14 | #define ElementType int 15 | #define ValArrayInterface ValArrayIntInterface 16 | #define ValArray ValArrayInt 17 | #define iValArrayInterface iValArrayInt 18 | #define MaxElementType INT_MAX 19 | #define MinElementType INT_MIN 20 | #define __IS_INTEGER__ 21 | static const guid ValArrayGuidInt = {0xe4386077, 0x540f, 0x4ec0, {0xac,0x95,0xa0,0x96,0x10,0x98,0xc4,0x7f}}; 22 | #define ValArrayGuid ValArrayGuidInt 23 | #include "valarraygen.c" 24 | #undef __IS_INTEGER__ 25 | -------------------------------------------------------------------------------- /valarraylongdouble.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "containers.h" 3 | #include "ccl_internal.h" 4 | /**************************************************************************** 5 | * ValArrayLongDouble * 6 | ****************************************************************************/ 7 | #undef ElementType 8 | #undef ValArrayInterface 9 | #undef ElementType 10 | #undef ValArray 11 | #undef tagValArray 12 | #undef _ValArray 13 | #define _ValArray _ValArrayLongDouble 14 | #define tagValArray tagValArrayLongDoubleInterface 15 | #define ElementType long double 16 | #define ValArrayInterface ValArrayLongDoubleInterface 17 | #define ValArray ValArrayLongDouble 18 | #define iValArrayInterface iValArrayLongDouble 19 | #define MaxElementType LDBL_MAX 20 | #define MinElementType LDBL_MIN 21 | static const guid ValArrayGuidLongDouble = {0xd0c2db6e, 0x2120, 0x40e8, 22 | {0xa0,0x33,0x4a,0x1e,0xd7,0x12,0x32,0x80} 23 | }; 24 | #define ValArrayGuid ValArrayGuidLongDouble 25 | #include "valarraygen.c" 26 | -------------------------------------------------------------------------------- /valarraylonglong.c: -------------------------------------------------------------------------------- 1 | #include "containers.h" 2 | #include "ccl_internal.h" 3 | /**************************************************************************** 4 | * ValArrayLLong * 5 | ****************************************************************************/ 6 | #undef ElementType 7 | #undef ValArrayInterface 8 | #undef ElementType 9 | #undef ValArray 10 | #undef tagValArray 11 | #undef _ValArray 12 | #define _ValArray _ValArrayLLong 13 | #define tagValArray tagValArrayLLongInterface 14 | #define ElementType long long 15 | #define ValArrayInterface ValArrayLLongInterface 16 | #define ValArray ValArrayLLong 17 | #define iValArrayInterface iValArrayLLong 18 | #define __IS_INTEGER__ 19 | #define MaxElementType LLONG_MAX 20 | #define MinElementType LLONG_MIN 21 | static const guid ValArrayGuidLLong = {0xe4386077, 0x540f, 0x4ec0, {0xac,0x95,0xa0,0x96,0x10,0x98,0xc4,0x7f}}; 22 | #define ValArrayGuid ValArrayGuidLLong 23 | #include "valarraygen.c" 24 | #undef __IS_INTEGER__ 25 | -------------------------------------------------------------------------------- /valarrayshort.c: -------------------------------------------------------------------------------- 1 | #include "containers.h" 2 | #include "ccl_internal.h" 3 | /**************************************************************************** 4 | * ValArrayShort * 5 | ****************************************************************************/ 6 | #undef ElementType 7 | #undef ValArrayShorterface 8 | #undef ElementType 9 | #undef ValArray 10 | #undef tagValArray 11 | #undef _ValArray 12 | #define _ValArray _ValArrayShort 13 | #define tagValArray tagValArrayShortInterface 14 | #define ElementType short 15 | #define ValArrayInterface ValArrayShortInterface 16 | #define ValArray ValArrayShort 17 | #define iValArrayInterface iValArrayShort 18 | #define MinElementType SHRT_MIN 19 | #define MaxElementType SHRT_MAX 20 | static const guid ValArrayGuidShort = {0x85a86bdd, 0xeca1, 0x4966, 21 | {0x8d,0x1a,0x78,0x38,0x89,0x0,0x87,0xb4} 22 | }; 23 | #define ValArrayGuid ValArrayGuidShort 24 | #define __IS_INTEGER__ 25 | #include "valarraygen.c" 26 | -------------------------------------------------------------------------------- /valarraysize_t.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * ValArraySize_t * 3 | ****************************************************************************/ 4 | #include "containers.h" 5 | #include "ccl_internal.h" 6 | 7 | #undef ElementType 8 | #undef ValArrayInterface 9 | #undef ElementType 10 | #undef ValArray 11 | #undef tagValArray 12 | #undef _ValArray 13 | #define _ValArray _ValArraySize_t 14 | #define tagValArray tagValArraySize_tInterface 15 | #define ElementType size_t 16 | #define ValArrayInterface ValArraySize_tInterface 17 | #define ValArray ValArraySize_t 18 | #define iValArrayInterface iValArraySize_t 19 | /* This supposes size_t is unsigned */ 20 | #define MaxElementType (ElementType)-1 21 | #define MinElementType 0 22 | static const guid ValArrayGuidSize_t = {0x39058047, 0x42ec, 0x4c0e, 23 | {0xb3,0xb7,0xc,0x50,0x38,0xcd,0x24,0x8} 24 | }; 25 | #define ValArrayGuid ValArrayGuidSize_t 26 | #define __IS_UNSIGNED__ 27 | #define __IS_INTEGER__ 28 | #include "valarraygen.c" 29 | -------------------------------------------------------------------------------- /valarrayuint.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "containers.h" 3 | #include "ccl_internal.h" 4 | /**************************************************************************** 5 | * ValArrayUInt * 6 | ****************************************************************************/ 7 | #undef ElementType 8 | #undef ValArrayInterface 9 | #undef ElementType 10 | #undef ValArray 11 | #undef tagValArray 12 | #undef _ValArray 13 | #define _ValArray _ValArrayUInt 14 | #define tagValArray tagValArrayUIntInterface 15 | #define ElementType unsigned 16 | #define ValArrayInterface ValArrayUIntInterface 17 | #define ValArray ValArrayUInt 18 | #define iValArrayInterface iValArrayUInt 19 | #define MaxElementType UINT_MAX 20 | #define MinElementType 0 21 | #define __IS_UNSIGNED__ 22 | #define __IS_INTEGER__ 23 | static const guid ValArrayGuidUInt = {0x597348e1, 0xe84, 0x4959, {0xae,0x1c,0x62,0x57,0xa8,0xa0,0xea,0x9d}}; 24 | #define ValArrayGuid ValArrayGuidUInt 25 | #include "valarraygen.c" 26 | -------------------------------------------------------------------------------- /valarrayulonglong.c: -------------------------------------------------------------------------------- 1 | #include "containers.h" 2 | #include "ccl_internal.h" 3 | /**************************************************************************** 4 | * ValArrayULLong * 5 | ****************************************************************************/ 6 | #undef ElementType 7 | #undef ValArrayInterface 8 | #undef ElementType 9 | #undef ValArray 10 | #undef tagValArray 11 | #undef _ValArray 12 | #define _ValArray _ValArrayULLong 13 | #define tagValArray tagValArrayULLongInterface 14 | #define ElementType unsigned long long 15 | #define ValArrayInterface ValArrayULLongInterface 16 | #define ValArray ValArrayULLong 17 | #define iValArrayInterface iValArrayULLong 18 | #define __IS_INTEGER__ 19 | #define MaxElementType ULLONG_MAX 20 | #define MinElementType 0 21 | static const guid ValArrayGuidULLong = {0x209022f8, 0x4f50, 0x4437, {0x93,0xb1,0xe6,0xc5,0xf5,0x6f,0x47,0xde} 22 | }; 23 | 24 | #define ValArrayGuid ValArrayGuidULLong 25 | #define __IS_UNSIGNED__ 26 | #include "valarraygen.c" 27 | #undef __IS_INTEGER__ 28 | -------------------------------------------------------------------------------- /vectorgen.c: -------------------------------------------------------------------------------- 1 | #include "containers.h" 2 | #include "ccl_internal.h" 3 | #include "vectorgen.h" 4 | #ifndef DEFAULT_START_SIZE 5 | #define DEFAULT_START_SIZE 20 6 | #endif 7 | 8 | static VECTOR_TYPE *SetVTable(VECTOR_TYPE *result); 9 | 10 | static int NullPtrError(const char *fnName) 11 | { 12 | char buf[512]; 13 | 14 | snprintf(buf,sizeof(buf),"iVector.%s",fnName); 15 | return iError.NullPtrError(buf); 16 | } 17 | 18 | static int Add(VECTOR_TYPE * l, const DATA_TYPE elem) 19 | { 20 | return iVector.Add((Vector *)l,&elem); 21 | } 22 | 23 | static VECTOR_TYPE *GetRange(const VECTOR_TYPE *AL, size_t start,size_t end) 24 | { 25 | VECTOR_TYPE *result=(VECTOR_TYPE *)iVector.GetRange((Vector *)AL,start,end); 26 | return SetVTable(result); 27 | } 28 | 29 | static int Contains(const VECTOR_TYPE * l, const DATA_TYPE data,void *ExtraArgs) 30 | { 31 | size_t idx; 32 | return (iVector.IndexOf((Vector *)l, &data, ExtraArgs, &idx) < 0) ? 0 : 1; 33 | } 34 | 35 | static VECTOR_TYPE *Copy(const VECTOR_TYPE * l) 36 | { 37 | VECTOR_TYPE *result = (VECTOR_TYPE *)iVector.Copy((Vector *)l); 38 | return SetVTable(result); 39 | } 40 | 41 | 42 | static void **CopyTo(const VECTOR_TYPE *AL) 43 | { 44 | return iVector.CopyTo((Vector *)AL); 45 | } 46 | 47 | static int IndexOf(const VECTOR_TYPE *AL,const DATA_TYPE data,void *ExtraArgs,size_t *result) 48 | { 49 | return iVector.IndexOf((Vector *)AL,&data,ExtraArgs,result); 50 | } 51 | 52 | static int InsertAt(VECTOR_TYPE *AL,size_t idx,DATA_TYPE newval) 53 | { 54 | return iVector.InsertAt((Vector *)AL, idx,&newval);; 55 | } 56 | 57 | static int Insert(VECTOR_TYPE *AL,DATA_TYPE newval) 58 | { 59 | return iVector.InsertAt((Vector *)AL,0,&newval); 60 | } 61 | 62 | static int Erase(VECTOR_TYPE *AL, DATA_TYPE elem) 63 | { 64 | return iVector.Erase((Vector *)AL, &elem); 65 | } 66 | static int EraseAll(VECTOR_TYPE *AL, DATA_TYPE elem) 67 | { 68 | return iVector.EraseAll((Vector *)AL, &elem);; 69 | } 70 | 71 | static int PushBack(VECTOR_TYPE *AL,const DATA_TYPE data) 72 | { 73 | return iVector.PushBack((Vector *)AL,&data); 74 | } 75 | 76 | static int PopBack(VECTOR_TYPE *AL,DATA_TYPE result) 77 | { 78 | return iVector.PushBack((Vector *)AL,&result);; 79 | } 80 | 81 | /*------------------------------------------------------------------------ 82 | Procedure: ReplaceAt ID:1 83 | Purpose: Replace the data at the given position with new 84 | data. 85 | Input: The list and the new data 86 | Output: Returns the new data if OK, NULL if error. 87 | Errors: Index error or read only errors are caught 88 | ------------------------------------------------------------------------*/ 89 | static int ReplaceAt(VECTOR_TYPE *AL,size_t idx,DATA_TYPE newval) 90 | { 91 | return iVector.ReplaceAt((Vector *)AL,idx,&newval); 92 | } 93 | 94 | static size_t Sizeof(const VECTOR_TYPE *AL) 95 | { 96 | if (AL == NULL) 97 | return sizeof(VECTOR_TYPE); 98 | return sizeof(VECTOR_TYPE) + (AL->count * sizeof(DATA_TYPE)); 99 | } 100 | 101 | static int Sort(VECTOR_TYPE *AL) 102 | { 103 | CompareInfo ci; 104 | 105 | if (AL == NULL) { 106 | return NullPtrError("Sort"); 107 | } 108 | ci.ContainerLeft = AL; 109 | ci.ExtraArgs = NULL; 110 | qsortEx(AL->contents,AL->count,AL->ElementSize,AL->CompareFn,&ci); 111 | return 1; 112 | } 113 | 114 | 115 | /* ------------------------------------------------------------------------------ */ 116 | /* Iterators */ 117 | /* ------------------------------------------------------------------------------ */ 118 | 119 | 120 | static int ReplaceWithIterator(Iterator * it, DATA_TYPE data, int direction) 121 | { 122 | struct ITERATOR(DATA_TYPE) *iter = (struct ITERATOR(DATA_TYPE) *)it; 123 | return iter->VectorReplace(it,&data,direction); 124 | } 125 | 126 | static Iterator *SetupIteratorVTable(struct ITERATOR(DATA_TYPE) *result) 127 | { 128 | if (result == NULL) return NULL; 129 | result->VectorReplace = result->it.Replace; 130 | result->it.Replace = (int (*)(Iterator * , void * , int ))ReplaceWithIterator; 131 | return &result->it; 132 | } 133 | 134 | 135 | static Iterator *NewIterator(VECTOR_TYPE * L) 136 | { 137 | return SetupIteratorVTable((struct ITERATOR(DATA_TYPE) *)iVector.NewIterator((Vector *)L)); 138 | } 139 | 140 | 141 | static VECTOR_TYPE *Load(FILE * stream, ReadFunction loadFn, void *arg) 142 | { 143 | VECTOR_TYPE *result = (VECTOR_TYPE *)iVector.Load(stream,loadFn,arg); 144 | return SetVTable(result); 145 | } 146 | 147 | static int InitIterator(VECTOR_TYPE * L, void *r) 148 | { 149 | iVector.InitIterator((Vector *)L,r); 150 | SetupIteratorVTable(r); 151 | return 1; 152 | } 153 | 154 | 155 | static VECTOR_TYPE *SetVTable(VECTOR_TYPE *result) 156 | { 157 | static int Initialized; 158 | INTERFACE(DATA_TYPE) *intface = &INTERFACE_NAME(DATA_TYPE); 159 | 160 | result->VTable = intface; 161 | if (Initialized) return result; 162 | Initialized = 1; 163 | intface->Size = (size_t (*)(const VECTOR_TYPE *))iVector.Size; 164 | intface->SetFlags = (unsigned (*)(VECTOR_TYPE * l, unsigned newval))iVector.SetFlags; 165 | intface->GetFlags = (unsigned (*)(const VECTOR_TYPE *))iVector.GetFlags; 166 | intface->GetCapacity = (size_t (*)(const VECTOR_TYPE *))iVector.GetCapacity; 167 | intface->SetCapacity = (int (*)(VECTOR_TYPE *, size_t))iVector.SetCapacity; 168 | intface->Clear = (int (*)(VECTOR_TYPE *))iVector.Clear; 169 | intface->Finalize = (int (*)(VECTOR_TYPE *))iVector.Finalize; 170 | intface->Apply = (int (*)(VECTOR_TYPE *, int (Applyfn) (DATA_TYPE *, void * ), void *))iVector.Apply; 171 | intface->SetErrorFunction = (ErrorFunction (*)(VECTOR_TYPE *, ErrorFunction))iVector.SetErrorFunction; 172 | intface->Resize = (int (*)(VECTOR_TYPE *,size_t))iVector.Resize; 173 | intface->Save = (int (*)(const VECTOR_TYPE *, FILE *, SaveFunction, void *))iVector.Save; 174 | intface->IndexIn = (VECTOR_TYPE *(*)(VECTOR_TYPE *,const Vector *))iVector.IndexIn; 175 | intface->EraseAt = (int (*)(VECTOR_TYPE *AL,size_t idx))iVector.EraseAt; 176 | intface->InsertIn = (int (*)(VECTOR_TYPE *, size_t,VECTOR_TYPE *))iVector.InsertIn; 177 | intface->Append = (int (*)(VECTOR_TYPE *, VECTOR_TYPE *))iVector.Append; 178 | intface->RemoveRange = (int (*)(VECTOR_TYPE *,size_t,size_t))iVector.RemoveRange; 179 | intface->AddRange = (int (*)(VECTOR_TYPE *,size_t,const DATA_TYPE *))iVector.AddRange; 180 | intface->GetAllocator = (const ContainerAllocator * (*)(const VECTOR_TYPE *))iVector.GetAllocator; 181 | intface->Mismatch = (int (*)(VECTOR_TYPE *a1, VECTOR_TYPE *a2,size_t *mismatch))iVector.Mismatch; 182 | intface->SetCompareFunction = (CompareFunction (*)(VECTOR_TYPE *,CompareFunction))iVector.SetCompareFunction; 183 | intface->SelectCopy = (VECTOR_TYPE *(*)(VECTOR_TYPE *,Mask *))iVector.SelectCopy; 184 | intface->CopyElement = (int (*)(const VECTOR_TYPE *,size_t,DATA_TYPE *))iVector.CopyElement; 185 | intface->Reverse = (int (*)(VECTOR_TYPE *))iVector.Reverse; 186 | intface->SetDestructor = (DestructorFunction (*)(VECTOR_TYPE *,DestructorFunction))iVector.SetDestructor; 187 | intface->SearchWithKey = (int (*)(VECTOR_TYPE *,size_t,size_t ,size_t,DATA_TYPE,size_t *))iVector.SearchWithKey; 188 | intface->Select = (int (*)(VECTOR_TYPE *src,const Mask *m))iVector.Select; 189 | intface->GetData = (DATA_TYPE *(*)(const VECTOR_TYPE *))iVector.GetData; 190 | intface->RotateLeft = (int (*)(VECTOR_TYPE *V,size_t n))iVector.RotateLeft; 191 | intface->RotateRight = (int (*)(VECTOR_TYPE *V,size_t n))iVector.RotateRight; 192 | intface->CompareEqual = (Mask *(*)(const VECTOR_TYPE *,const VECTOR_TYPE *,Mask *))iVector.CompareEqual; 193 | intface->GetElement = (DATA_TYPE *(*)(const VECTOR_TYPE *,size_t))iVector.GetElement; 194 | intface->Back = (DATA_TYPE *(*)(const VECTOR_TYPE *))iVector.Back; 195 | intface->Front = (DATA_TYPE *(*)(const VECTOR_TYPE *))iVector.Front; 196 | 197 | return result; 198 | } 199 | 200 | static VECTOR_TYPE *CreateWithAllocator(size_t siz,const ContainerAllocator *a) 201 | { 202 | VECTOR_TYPE *r = (VECTOR_TYPE *)iVector.CreateWithAllocator(sizeof(DATA_TYPE),siz,a); 203 | if (r == NULL) return NULL; 204 | return SetVTable(r); 205 | } 206 | 207 | static VECTOR_TYPE *Create(size_t startsize) 208 | { 209 | return CreateWithAllocator(startsize,CurrentAllocator); 210 | } 211 | 212 | static VECTOR_TYPE *InitializeWith(size_t n,const DATA_TYPE *data) 213 | { 214 | VECTOR_TYPE *result = Create(n); 215 | if (result) { 216 | memcpy(result->contents,data,n*sizeof(DATA_TYPE)); 217 | result->count = n; 218 | } 219 | return result; 220 | } 221 | 222 | 223 | static VECTOR_TYPE *Init(VECTOR_TYPE *result,size_t startsize) 224 | { 225 | VECTOR_TYPE *r = (VECTOR_TYPE *)iVector.Init((Vector *)result,sizeof(DATA_TYPE),startsize); 226 | return SetVTable(r); 227 | } 228 | 229 | static size_t GetElementSize(const VECTOR_TYPE *AL) 230 | { 231 | return sizeof(DATA_TYPE); 232 | } 233 | 234 | static size_t SizeofIterator(const VECTOR_TYPE * l) 235 | { 236 | return sizeof(struct ITERATOR(DATA_TYPE)); 237 | } 238 | 239 | static Mask *CompareEqualScalar(const VECTOR_TYPE *left,const DATA_TYPE right,Mask *bytearray) 240 | { 241 | return iVector.CompareEqualScalar((Vector *)left,&right,bytearray); 242 | } 243 | 244 | INTERFACE(DATA_TYPE) INTERFACE_NAME(DATA_TYPE) = { 245 | NULL, // Size, 246 | NULL, // GetFlags, 247 | NULL, // SetFlags, 248 | NULL, // Clear, 249 | Contains, 250 | Erase, 251 | EraseAll, 252 | NULL, // Finalize, 253 | NULL, // Apply, 254 | NULL, // Equal, 255 | Copy, 256 | NULL, // SetErrorFunction, 257 | Sizeof, 258 | NewIterator, 259 | InitIterator, 260 | NULL, // deleteIterator, 261 | SizeofIterator, 262 | NULL, // Save, 263 | Load, 264 | GetElementSize, 265 | /* Sequential container fields */ 266 | Add, 267 | NULL, // GetElement, 268 | PushBack, 269 | PopBack, 270 | InsertAt, 271 | NULL, // EraseAt, 272 | ReplaceAt, 273 | IndexOf, 274 | /* Vector specific fields */ 275 | Insert, 276 | NULL, // InsertIn, 277 | NULL, // IndexIn, 278 | NULL, // GetCapacity, 279 | NULL, // SetCapacity, 280 | NULL, // SetCompareFunction, 281 | Sort, 282 | Create, 283 | CreateWithAllocator, 284 | Init, 285 | NULL, // AddRange, 286 | GetRange, 287 | NULL, // CopyElement, 288 | CopyTo, 289 | NULL, // Reverse, 290 | NULL, // Append, 291 | NULL, // Mismatch, 292 | NULL, // GetAllocator, 293 | NULL, // SetDestructor, 294 | NULL, // SearchWithKey, 295 | NULL, // Select, 296 | NULL, //SelectCopy, 297 | NULL, // Resize, 298 | InitializeWith, 299 | NULL, // GetData, 300 | NULL, // Back, 301 | NULL, // Front, 302 | NULL, // RemoveRange, 303 | NULL, // RotateLeft, 304 | NULL, // RotateRight, 305 | NULL, // CompareEqual, 306 | CompareEqualScalar, 307 | NULL, // Reserve 308 | }; 309 | -------------------------------------------------------------------------------- /vectorgen.h: -------------------------------------------------------------------------------- 1 | #ifndef DATA_TYPE 2 | #error "The symbol DATA_TYPE MUST be defined" 3 | #else 4 | #ifndef DEFAULT_START_SIZE 5 | #define DEFAULT_START_SIZE 20 6 | #endif 7 | #ifndef INT_MAX 8 | #define INT_MAX (((unsigned)-1) >> 1) 9 | #endif 10 | #undef VECTOR_TYPE 11 | #undef VECTOR_TYPE_ 12 | #undef INTERFACE 13 | #undef ITERATOR 14 | #undef ITERFACE_NAME 15 | #undef VECTOR_ELEMENT 16 | #undef INTERFACE_STRUCT_INTERNAL_NAME 17 | 18 | #define CONCAT(x,y) x ## y 19 | #define CONCAT3_(a,b,c) a##b##c 20 | #define CONCAT3(a,b,c) CONCAT3_(a,b,c) 21 | #define EVAL(t) t 22 | #define INTERFACE(t) CONCAT(t,VectorInterface) 23 | #define ITERATOR(t) CONCAT(t,VectorIterator) 24 | #define ERROR_RETURN 0 25 | 26 | #define VECTOR_TYPE_(t) CONCAT(t,Vector) 27 | #define VECTOR_TYPE VECTOR_TYPE_(DATA_TYPE) 28 | #define INTERFACE_NAME(a) CONCAT3(i,EVAL(a),Vector) 29 | #define VECTOR_STRUCT_INTERNAL_NAME(a) CONCAT3(__,EVAL(a),Vector) 30 | #define INTERFACE_STRUCT_INTERNAL_NAME(a) CONCAT3(__,EVAL(a),VectorInterface) 31 | 32 | typedef struct VECTOR_STRUCT_INTERNAL_NAME(DATA_TYPE) VECTOR_TYPE; 33 | typedef struct INTERFACE_STRUCT_INTERNAL_NAME(DATA_TYPE) INTERFACE(DATA_TYPE); 34 | struct VECTOR_STRUCT_INTERNAL_NAME(DATA_TYPE) { 35 | INTERFACE(DATA_TYPE) *VTable; /* Methods table */ 36 | size_t count; /* in elements units */ 37 | unsigned Flags; 38 | unsigned timestamp; /* Changed at each modification */ 39 | size_t ElementSize; /* Size (in bytes) of each element */ 40 | DATA_TYPE *contents; /* The data */ 41 | CompareFunction CompareFn; /* Element comparison function */ 42 | ErrorFunction RaiseError; /* Error function */ 43 | ContainerHeap *Heap; 44 | const ContainerAllocator *Allocator; 45 | DestructorFunction DestructorFn; 46 | }; 47 | 48 | struct ITERATOR(DATA_TYPE) { 49 | Iterator it; 50 | VECTOR_TYPE *L; 51 | size_t index; 52 | unsigned timestamp; 53 | unsigned long Flags; 54 | DATA_TYPE *Current; 55 | DATA_TYPE ElementBuffer; 56 | int (*VectorReplace)(struct _Iterator *,void *data,int direction); 57 | }; 58 | extern INTERFACE(DATA_TYPE) INTERFACE_NAME(DATA_TYPE); 59 | 60 | struct INTERFACE_STRUCT_INTERNAL_NAME(DATA_TYPE) { 61 | size_t (*Size)(const VECTOR_TYPE *AL); 62 | unsigned (*GetFlags)(const VECTOR_TYPE *AL); 63 | unsigned (*SetFlags)(VECTOR_TYPE *AL,unsigned flags); 64 | int (*Clear)(VECTOR_TYPE *AL); 65 | /*Case sensitive search of a character string in the data */ 66 | int (*Contains)(const VECTOR_TYPE *AL,const DATA_TYPE element,void *ExtraArgs); 67 | int (*Erase)(VECTOR_TYPE *AL,const DATA_TYPE elem); 68 | int (*EraseAll)(VECTOR_TYPE *AL,const DATA_TYPE elem); 69 | int (*Finalize)(VECTOR_TYPE *AL); 70 | int (*Apply)(VECTOR_TYPE *AL,int (*Applyfn)(DATA_TYPE *element,void * arg),void *arg); 71 | int (*Equal)(const VECTOR_TYPE *first,const VECTOR_TYPE *second); 72 | VECTOR_TYPE *(*Copy)(const VECTOR_TYPE *AL); 73 | ErrorFunction (*SetErrorFunction)(VECTOR_TYPE *AL,ErrorFunction); 74 | size_t (*Sizeof)(const VECTOR_TYPE *AL); 75 | Iterator *(*NewIterator)(VECTOR_TYPE *AL); 76 | int (*InitIterator)(VECTOR_TYPE *V,void *buf); 77 | int (*deleteIterator)(Iterator *); 78 | size_t (*SizeofIterator)(const VECTOR_TYPE *); 79 | int (*Save)(const VECTOR_TYPE *AL,FILE *stream, SaveFunction saveFn,void *arg); 80 | VECTOR_TYPE *(*Load)(FILE *stream, ReadFunction readFn,void *arg); 81 | size_t (*GetElementSize)(const VECTOR_TYPE *AL); 82 | 83 | /* Sequential container specific fields */ 84 | 85 | int (*Add)(VECTOR_TYPE *AL,const DATA_TYPE newval); 86 | DATA_TYPE *(*GetElement)(const VECTOR_TYPE *AL,size_t idx); 87 | int (*PushBack)(VECTOR_TYPE *AL,const DATA_TYPE str); 88 | int (*PopBack)(VECTOR_TYPE *AL,DATA_TYPE result); 89 | int (*InsertAt)(VECTOR_TYPE *AL,size_t idx,DATA_TYPE newval); 90 | int (*EraseAt)(VECTOR_TYPE *AL,size_t idx); 91 | int (*ReplaceAt)(VECTOR_TYPE *AL,size_t idx,DATA_TYPE newval); 92 | int (*IndexOf)(const VECTOR_TYPE *AL,const DATA_TYPE data,void *ExtraArgs,size_t *result); 93 | 94 | /* VECTOR_TYPE container specific fields */ 95 | 96 | int (*Insert)(VECTOR_TYPE *AL,DATA_TYPE elem); 97 | int (*InsertIn)(VECTOR_TYPE *AL, size_t idx,VECTOR_TYPE *newData); 98 | VECTOR_TYPE *(*IndexIn)(VECTOR_TYPE *SC,const Vector *AL); 99 | size_t (*GetCapacity)(const VECTOR_TYPE *AL); 100 | int (*SetCapacity)(VECTOR_TYPE *AL,size_t newCapacity); 101 | 102 | CompareFunction (*SetCompareFunction)(VECTOR_TYPE *l,CompareFunction fn); 103 | int (*Sort)(VECTOR_TYPE *AL); 104 | VECTOR_TYPE *(*Create)(size_t startsize); 105 | VECTOR_TYPE *(*CreateWithAllocator)(size_t startsiz,const ContainerAllocator *mm); 106 | VECTOR_TYPE *(*Init)(VECTOR_TYPE *r,size_t startsize); 107 | int (*AddRange)(VECTOR_TYPE *AL,size_t n,const DATA_TYPE *newvalues); 108 | VECTOR_TYPE *(*GetRange)(const VECTOR_TYPE *AL, size_t start, size_t end); 109 | int (*CopyElement)(const VECTOR_TYPE *AL,size_t idx,DATA_TYPE *outbuf); 110 | void **(*CopyTo)(const VECTOR_TYPE *AL); 111 | int (*Reverse)(VECTOR_TYPE *AL); 112 | int (*Append)(VECTOR_TYPE *AL1, VECTOR_TYPE *AL2); 113 | int (*Mismatch)(VECTOR_TYPE *a1,VECTOR_TYPE *a2,size_t *mismatch); 114 | const ContainerAllocator *(*GetAllocator)(const VECTOR_TYPE *AL); 115 | DestructorFunction (*SetDestructor)(VECTOR_TYPE *v,DestructorFunction fn); 116 | int (*SearchWithKey)(VECTOR_TYPE *vec,size_t startByte,size_t sizeKey,size_t startIndex,DATA_TYPE item,size_t *result); 117 | int (*Select)(VECTOR_TYPE *src,const Mask *m); 118 | VECTOR_TYPE *(*SelectCopy)(VECTOR_TYPE *src,Mask *m); 119 | int (*Resize)(VECTOR_TYPE *AL,size_t newSize); 120 | VECTOR_TYPE *(*InitializeWith)(size_t n,const DATA_TYPE *Data); 121 | DATA_TYPE *(*GetData)(const VECTOR_TYPE *AL); 122 | DATA_TYPE *(*Back)(const VECTOR_TYPE *AL); 123 | DATA_TYPE *(*Front)(const VECTOR_TYPE *AL); 124 | int (*RemoveRange)(VECTOR_TYPE *SC,size_t start,size_t end); 125 | int (*RotateLeft)(VECTOR_TYPE *V,size_t n); 126 | int (*RotateRight)(VECTOR_TYPE *V,size_t n); 127 | Mask *(*CompareEqual)(const VECTOR_TYPE *left,const VECTOR_TYPE *right,Mask *m); 128 | Mask *(*CompareEqualScalar)(const VECTOR_TYPE *left, const DATA_TYPE right,Mask *m); 129 | int (*Reserve)(VECTOR_TYPE *src,size_t newCapacity); 130 | }; 131 | #endif 132 | -------------------------------------------------------------------------------- /vectorsize_t.c: -------------------------------------------------------------------------------- 1 | #include "containers.h" 2 | #undef DATA_TYPE 3 | #define DATA_TYPE size_t 4 | #include "vectorgen.c" 5 | -------------------------------------------------------------------------------- /wdictionary.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "containers.h" 4 | #include "ccl_internal.h" 5 | #include "assert.h" 6 | #undef ITERATOR 7 | #undef INTERFACE 8 | #undef DATA_TYPE 9 | 10 | #define HASHFUNCTION WHashFunction 11 | #define ITERATOR WDictionaryIterator 12 | #define CHARTYPE wchar_t 13 | #define DATALIST WDataList 14 | #define DATA_TYPE WDictionary 15 | #define INTERFACE WDictionaryInterface 16 | #define EXTERNAL_NAME iWDictionary 17 | #define STRCPY wcscpy 18 | #define STRCMP wcscmp 19 | #define STRLEN wcslen 20 | #define iSTRCOLLECTION iWstrCollection 21 | #define STRCOLLECTION WstrCollection 22 | 23 | #include "dictionarygen.c" 24 | -------------------------------------------------------------------------------- /wstrcollection.c: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------ 2 | Module: wstrcollection.c 3 | Author: jacob 4 | Project: Containers 5 | State: 6 | Creation Date: 7 | Description: Implements the string collection container. 8 | Added fixes from Gerome. Oct. 20 2005 9 | ------------------------------------------------------------------------*/ 10 | #include 11 | #include "containers.h" 12 | #include "ccl_internal.h" 13 | #define WCHAR_TYPE 14 | #define CHAR_TYPE wchar_t 15 | #define SNPRINTF swprintf 16 | #define STRCMP wcscmp 17 | #define STRICMP wcscasecmp 18 | #define STRCPY wcscpy 19 | #define STRLEN wcslen 20 | #define _TCHAR(a) L##a 21 | #define ElementType WstrCollection 22 | #define iElementType iWstrCollection 23 | #define STRSTR wcsstr 24 | #define GETLINE WGetLine 25 | #define STRCOMPAREFUNCTION WStringCompareFn 26 | #define INTERFACE_TYP WstrCollectionInterface 27 | #define INTERFACE_OBJECT iWstrCollection 28 | #define NEWLINE L'\n' 29 | 30 | 31 | static const guid strCollectionGuid = {0x64bea19b, 0x243b, 0x487a, 32 | {0x9a,0xd6,0xcd,0xfe,0xa9,0x37,0x6e,0x89} 33 | }; 34 | 35 | #include "strcollectiongen.c" 36 | -------------------------------------------------------------------------------- /wstringlist.c: -------------------------------------------------------------------------------- 1 | #include "containers.h" 2 | #include "ccl_internal.h" 3 | #include 4 | #define CHARTYPE wchar_t 5 | #define STRCPY wcscpy 6 | #define STRLEN wcslen 7 | #define STRCMP wcscmp 8 | #define DATA_TYPE wString 9 | #define StringListGuid WStringListGuid 10 | static const guid WStringListGuid = {0xA0543963,0xCBAC,0x4AFB, 11 | {0x09,0xC0,0xA1,0x40,0x79,0x32,0x8D,0x7B} 12 | }; 13 | 14 | #include "stringlistgen.c" 15 | 16 | #undef CHARTYPE 17 | #undef STRCPY 18 | #undef STRLEN 19 | #undef STRCMP 20 | #undef iSTRINGLIST 21 | #undef INTERFACE 22 | #undef LIST_ELEMENT 23 | #undef LIST_TYPE 24 | #undef LIST_TYPE_Iterator 25 | 26 | -------------------------------------------------------------------------------- /wstringlist.h: -------------------------------------------------------------------------------- 1 | #include 2 | #undef CHARTYPE 3 | #undef DATA_TYPE 4 | 5 | #define DATA_TYPE wString 6 | #define CHARTYPE wchar_t 7 | #include "stringlistgen.h" 8 | --------------------------------------------------------------------------------