1 /* Copyright JS Foundation and other contributors, http://js.foundation 2 * 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef ECMA_PROPERTY_HASHMAP_H 17 #define ECMA_PROPERTY_HASHMAP_H 18 19 /** \addtogroup ecma ECMA 20 * @{ 21 * 22 * \addtogroup ecmapropertyhashmap Property hashmap 23 * @{ 24 */ 25 26 /** 27 * Recommended minimum number of items in a property cache. 28 */ 29 #define ECMA_PROPERTY_HASMAP_MINIMUM_SIZE 32 30 31 /** 32 * Property hash. 33 */ 34 typedef struct 35 { 36 ecma_property_header_t header; /**< header of the property */ 37 uint32_t max_property_count; /**< maximum property count (power of 2) */ 38 uint32_t null_count; /**< number of NULLs in the map */ 39 uint32_t unused_count; /**< number of unused entires in the map */ 40 41 /* 42 * The hash is followed by max_property_count ecma_cpointer_t 43 * compressed pointers and (max_property_count + 7) / 8 bytes 44 * which stores a flag for each compressed pointer. 45 * 46 * If the compressed pointer is equal to ECMA_NULL_POINTER 47 * - flag is cleared if the entry is NULL 48 * - flag is set if the entry is deleted 49 * 50 * If the compressed pointer is not equal to ECMA_NULL_POINTER 51 * - flag is cleared if the first entry of a property pair is referenced 52 * - flag is set if the second entry of a property pair is referenced 53 */ 54 } ecma_property_hashmap_t; 55 56 #if ENABLED (JERRY_PROPRETY_HASHMAP) 57 58 /** 59 * Simple ecma values 60 */ 61 typedef enum 62 { 63 ECMA_PROPERTY_HASHMAP_DELETE_NO_HASHMAP, /**< object has no hashmap */ 64 ECMA_PROPERTY_HASHMAP_DELETE_HAS_HASHMAP, /**< object has hashmap */ 65 ECMA_PROPERTY_HASHMAP_DELETE_RECREATE_HASHMAP, /**< hashmap should be recreated */ 66 } ecma_property_hashmap_delete_status; 67 68 void ecma_property_hashmap_create (ecma_object_t *object_p); 69 void ecma_property_hashmap_free (ecma_object_t *object_p); 70 void ecma_property_hashmap_insert (ecma_object_t *object_p, ecma_string_t *name_p, 71 ecma_property_pair_t *property_pair_p, int property_index); 72 ecma_property_hashmap_delete_status ecma_property_hashmap_delete (ecma_object_t *object_p, jmem_cpointer_t name_cp, 73 ecma_property_t *property_p); 74 75 ecma_property_t *ecma_property_hashmap_find (ecma_property_hashmap_t *hashmap_p, ecma_string_t *name_p, 76 jmem_cpointer_t *property_real_name_cp); 77 #endif /* ENABLED (JERRY_PROPRETY_HASHMAP) */ 78 79 /** 80 * @} 81 * @} 82 */ 83 84 #endif /* !ECMA_PROPERTY_HASHMAP_H */ 85