universe@706: /* universe@706: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. universe@706: * universe@706: * Copyright 2023 Mike Becker, Olaf Wintermann All rights reserved. universe@706: * universe@706: * Redistribution and use in source and binary forms, with or without universe@706: * modification, are permitted provided that the following conditions are met: universe@706: * universe@706: * 1. Redistributions of source code must retain the above copyright universe@706: * notice, this list of conditions and the following disclaimer. universe@706: * universe@706: * 2. Redistributions in binary form must reproduce the above copyright universe@706: * notice, this list of conditions and the following disclaimer in the universe@706: * documentation and/or other materials provided with the distribution. universe@706: * universe@706: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" universe@706: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE universe@706: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE universe@706: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE universe@706: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR universe@706: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF universe@706: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS universe@706: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN universe@706: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) universe@706: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE universe@706: * POSSIBILITY OF SUCH DAMAGE. universe@706: */ universe@706: universe@706: #include "cx/map.h" universe@709: #include universe@706: universe@706: // universe@706: universe@706: static void cx_empty_map_noop(__attribute__((__unused__)) CxMap *map) { universe@706: // this is a noop, but MUST be implemented universe@706: } universe@706: universe@706: static void *cx_empty_map_get( universe@706: __attribute__((__unused__)) CxMap const *map, universe@706: __attribute__((__unused__)) CxHashKey key universe@706: ) { universe@706: return NULL; universe@706: } universe@706: universe@706: static bool cx_empty_map_iter_valid(__attribute__((__unused__)) void const *iter) { universe@706: return false; universe@706: } universe@706: universe@709: static CxIterator cx_empty_map_iterator( universe@709: struct cx_map_s const *map, universe@709: __attribute__((__unused__)) enum cx_map_iterator_type type universe@709: ) { universe@706: CxIterator iter = {0}; universe@706: iter.src_handle = map; universe@706: iter.base.valid = cx_empty_map_iter_valid; universe@706: return iter; universe@706: } universe@706: universe@706: static struct cx_map_class_s cx_empty_map_class = { universe@709: cx_empty_map_noop, universe@709: cx_empty_map_noop, universe@709: NULL, universe@709: cx_empty_map_get, universe@709: NULL, universe@709: cx_empty_map_iterator universe@706: }; universe@706: universe@706: CxMap cx_empty_map = { universe@706: NULL, universe@706: NULL, universe@706: 0, universe@706: 0, universe@706: NULL, universe@706: NULL, universe@706: NULL, universe@706: false, universe@706: &cx_empty_map_class universe@706: }; universe@706: universe@709: CxMap *const cxEmptyMap = &cx_empty_map; universe@706: universe@706: // universe@709: universe@709: CxMutIterator cxMapMutIteratorValues(CxMap *map) { universe@709: CxIterator it = map->cl->iterator(map, CX_MAP_ITERATOR_VALUES); universe@709: it.base.mutating = true; universe@709: universe@709: // we know the iterators share the same memory layout universe@709: CxMutIterator iter; universe@709: memcpy(&iter, &it, sizeof(CxMutIterator)); universe@709: return iter; universe@709: } universe@709: universe@709: CxMutIterator cxMapMutIteratorKeys(CxMap *map) { universe@709: CxIterator it = map->cl->iterator(map, CX_MAP_ITERATOR_KEYS); universe@709: it.base.mutating = true; universe@709: universe@709: // we know the iterators share the same memory layout universe@709: CxMutIterator iter; universe@709: memcpy(&iter, &it, sizeof(CxMutIterator)); universe@709: return iter; universe@709: } universe@709: universe@709: CxMutIterator cxMapMutIterator(CxMap *map) { universe@709: CxIterator it = map->cl->iterator(map, CX_MAP_ITERATOR_PAIRS); universe@709: it.base.mutating = true; universe@709: universe@709: // we know the iterators share the same memory layout universe@709: CxMutIterator iter; universe@709: memcpy(&iter, &it, sizeof(CxMutIterator)); universe@709: return iter; universe@709: }