Sun, 31 Dec 2023 15:02:11 +0100
migrate compare tests - relates to #342
universe@706 | 1 | /* |
universe@706 | 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
universe@706 | 3 | * |
universe@706 | 4 | * Copyright 2023 Mike Becker, Olaf Wintermann All rights reserved. |
universe@706 | 5 | * |
universe@706 | 6 | * Redistribution and use in source and binary forms, with or without |
universe@706 | 7 | * modification, are permitted provided that the following conditions are met: |
universe@706 | 8 | * |
universe@706 | 9 | * 1. Redistributions of source code must retain the above copyright |
universe@706 | 10 | * notice, this list of conditions and the following disclaimer. |
universe@706 | 11 | * |
universe@706 | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
universe@706 | 13 | * notice, this list of conditions and the following disclaimer in the |
universe@706 | 14 | * documentation and/or other materials provided with the distribution. |
universe@706 | 15 | * |
universe@706 | 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
universe@706 | 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
universe@706 | 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
universe@706 | 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
universe@706 | 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
universe@706 | 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
universe@706 | 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
universe@706 | 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
universe@706 | 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
universe@706 | 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
universe@706 | 26 | * POSSIBILITY OF SUCH DAMAGE. |
universe@706 | 27 | */ |
universe@706 | 28 | |
universe@706 | 29 | #include "cx/map.h" |
universe@709 | 30 | #include <string.h> |
universe@706 | 31 | |
universe@706 | 32 | // <editor-fold desc="empty map implementation"> |
universe@706 | 33 | |
universe@706 | 34 | static void cx_empty_map_noop(__attribute__((__unused__)) CxMap *map) { |
universe@706 | 35 | // this is a noop, but MUST be implemented |
universe@706 | 36 | } |
universe@706 | 37 | |
universe@706 | 38 | static void *cx_empty_map_get( |
universe@706 | 39 | __attribute__((__unused__)) CxMap const *map, |
universe@706 | 40 | __attribute__((__unused__)) CxHashKey key |
universe@706 | 41 | ) { |
universe@706 | 42 | return NULL; |
universe@706 | 43 | } |
universe@706 | 44 | |
universe@706 | 45 | static bool cx_empty_map_iter_valid(__attribute__((__unused__)) void const *iter) { |
universe@706 | 46 | return false; |
universe@706 | 47 | } |
universe@706 | 48 | |
universe@709 | 49 | static CxIterator cx_empty_map_iterator( |
universe@709 | 50 | struct cx_map_s const *map, |
universe@709 | 51 | __attribute__((__unused__)) enum cx_map_iterator_type type |
universe@709 | 52 | ) { |
universe@706 | 53 | CxIterator iter = {0}; |
universe@706 | 54 | iter.src_handle = map; |
universe@706 | 55 | iter.base.valid = cx_empty_map_iter_valid; |
universe@706 | 56 | return iter; |
universe@706 | 57 | } |
universe@706 | 58 | |
universe@706 | 59 | static struct cx_map_class_s cx_empty_map_class = { |
universe@709 | 60 | cx_empty_map_noop, |
universe@709 | 61 | cx_empty_map_noop, |
universe@709 | 62 | NULL, |
universe@709 | 63 | cx_empty_map_get, |
universe@709 | 64 | NULL, |
universe@709 | 65 | cx_empty_map_iterator |
universe@706 | 66 | }; |
universe@706 | 67 | |
universe@706 | 68 | CxMap cx_empty_map = { |
universe@706 | 69 | NULL, |
universe@706 | 70 | NULL, |
universe@706 | 71 | 0, |
universe@706 | 72 | 0, |
universe@706 | 73 | NULL, |
universe@706 | 74 | NULL, |
universe@706 | 75 | NULL, |
universe@706 | 76 | false, |
universe@706 | 77 | &cx_empty_map_class |
universe@706 | 78 | }; |
universe@706 | 79 | |
universe@709 | 80 | CxMap *const cxEmptyMap = &cx_empty_map; |
universe@706 | 81 | |
universe@706 | 82 | // </editor-fold> |
universe@709 | 83 | |
universe@709 | 84 | CxMutIterator cxMapMutIteratorValues(CxMap *map) { |
universe@709 | 85 | CxIterator it = map->cl->iterator(map, CX_MAP_ITERATOR_VALUES); |
universe@709 | 86 | it.base.mutating = true; |
universe@709 | 87 | |
universe@709 | 88 | // we know the iterators share the same memory layout |
universe@709 | 89 | CxMutIterator iter; |
universe@709 | 90 | memcpy(&iter, &it, sizeof(CxMutIterator)); |
universe@709 | 91 | return iter; |
universe@709 | 92 | } |
universe@709 | 93 | |
universe@709 | 94 | CxMutIterator cxMapMutIteratorKeys(CxMap *map) { |
universe@709 | 95 | CxIterator it = map->cl->iterator(map, CX_MAP_ITERATOR_KEYS); |
universe@709 | 96 | it.base.mutating = true; |
universe@709 | 97 | |
universe@709 | 98 | // we know the iterators share the same memory layout |
universe@709 | 99 | CxMutIterator iter; |
universe@709 | 100 | memcpy(&iter, &it, sizeof(CxMutIterator)); |
universe@709 | 101 | return iter; |
universe@709 | 102 | } |
universe@709 | 103 | |
universe@709 | 104 | CxMutIterator cxMapMutIterator(CxMap *map) { |
universe@709 | 105 | CxIterator it = map->cl->iterator(map, CX_MAP_ITERATOR_PAIRS); |
universe@709 | 106 | it.base.mutating = true; |
universe@709 | 107 | |
universe@709 | 108 | // we know the iterators share the same memory layout |
universe@709 | 109 | CxMutIterator iter; |
universe@709 | 110 | memcpy(&iter, &it, sizeof(CxMutIterator)); |
universe@709 | 111 | return iter; |
universe@709 | 112 | } |