1425bb815Sopenharmony_ci/* Copyright JS Foundation and other contributors, http://js.foundation
2425bb815Sopenharmony_ci *
3425bb815Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4425bb815Sopenharmony_ci * you may not use this file except in compliance with the License.
5425bb815Sopenharmony_ci * You may obtain a copy of the License at
6425bb815Sopenharmony_ci *
7425bb815Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8425bb815Sopenharmony_ci *
9425bb815Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10425bb815Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS
11425bb815Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12425bb815Sopenharmony_ci * See the License for the specific language governing permissions and
13425bb815Sopenharmony_ci * limitations under the License.
14425bb815Sopenharmony_ci */
15425bb815Sopenharmony_ci
16425bb815Sopenharmony_ci#ifndef ECMA_PROPERTY_HASHMAP_H
17425bb815Sopenharmony_ci#define ECMA_PROPERTY_HASHMAP_H
18425bb815Sopenharmony_ci
19425bb815Sopenharmony_ci/** \addtogroup ecma ECMA
20425bb815Sopenharmony_ci * @{
21425bb815Sopenharmony_ci *
22425bb815Sopenharmony_ci * \addtogroup ecmapropertyhashmap Property hashmap
23425bb815Sopenharmony_ci * @{
24425bb815Sopenharmony_ci */
25425bb815Sopenharmony_ci
26425bb815Sopenharmony_ci/**
27425bb815Sopenharmony_ci * Recommended minimum number of items in a property cache.
28425bb815Sopenharmony_ci */
29425bb815Sopenharmony_ci#define ECMA_PROPERTY_HASMAP_MINIMUM_SIZE 32
30425bb815Sopenharmony_ci
31425bb815Sopenharmony_ci/**
32425bb815Sopenharmony_ci * Property hash.
33425bb815Sopenharmony_ci */
34425bb815Sopenharmony_citypedef struct
35425bb815Sopenharmony_ci{
36425bb815Sopenharmony_ci  ecma_property_header_t header; /**< header of the property */
37425bb815Sopenharmony_ci  uint32_t max_property_count; /**< maximum property count (power of 2) */
38425bb815Sopenharmony_ci  uint32_t null_count; /**< number of NULLs in the map */
39425bb815Sopenharmony_ci  uint32_t unused_count; /**< number of unused entires in the map */
40425bb815Sopenharmony_ci
41425bb815Sopenharmony_ci  /*
42425bb815Sopenharmony_ci   * The hash is followed by max_property_count ecma_cpointer_t
43425bb815Sopenharmony_ci   * compressed pointers and (max_property_count + 7) / 8 bytes
44425bb815Sopenharmony_ci   * which stores a flag for each compressed pointer.
45425bb815Sopenharmony_ci   *
46425bb815Sopenharmony_ci   * If the compressed pointer is equal to ECMA_NULL_POINTER
47425bb815Sopenharmony_ci   *   - flag is cleared if the entry is NULL
48425bb815Sopenharmony_ci   *   - flag is set if the entry is deleted
49425bb815Sopenharmony_ci   *
50425bb815Sopenharmony_ci   * If the compressed pointer is not equal to ECMA_NULL_POINTER
51425bb815Sopenharmony_ci   *   - flag is cleared if the first entry of a property pair is referenced
52425bb815Sopenharmony_ci   *   - flag is set if the second entry of a property pair is referenced
53425bb815Sopenharmony_ci   */
54425bb815Sopenharmony_ci} ecma_property_hashmap_t;
55425bb815Sopenharmony_ci
56425bb815Sopenharmony_ci#if ENABLED (JERRY_PROPRETY_HASHMAP)
57425bb815Sopenharmony_ci
58425bb815Sopenharmony_ci/**
59425bb815Sopenharmony_ci * Simple ecma values
60425bb815Sopenharmony_ci */
61425bb815Sopenharmony_citypedef enum
62425bb815Sopenharmony_ci{
63425bb815Sopenharmony_ci  ECMA_PROPERTY_HASHMAP_DELETE_NO_HASHMAP, /**< object has no hashmap */
64425bb815Sopenharmony_ci  ECMA_PROPERTY_HASHMAP_DELETE_HAS_HASHMAP, /**< object has hashmap */
65425bb815Sopenharmony_ci  ECMA_PROPERTY_HASHMAP_DELETE_RECREATE_HASHMAP, /**< hashmap should be recreated */
66425bb815Sopenharmony_ci} ecma_property_hashmap_delete_status;
67425bb815Sopenharmony_ci
68425bb815Sopenharmony_civoid ecma_property_hashmap_create (ecma_object_t *object_p);
69425bb815Sopenharmony_civoid ecma_property_hashmap_free (ecma_object_t *object_p);
70425bb815Sopenharmony_civoid ecma_property_hashmap_insert (ecma_object_t *object_p, ecma_string_t *name_p,
71425bb815Sopenharmony_ci                                   ecma_property_pair_t *property_pair_p, int property_index);
72425bb815Sopenharmony_ciecma_property_hashmap_delete_status ecma_property_hashmap_delete (ecma_object_t *object_p, jmem_cpointer_t name_cp,
73425bb815Sopenharmony_ci                                                                  ecma_property_t *property_p);
74425bb815Sopenharmony_ci
75425bb815Sopenharmony_ciecma_property_t *ecma_property_hashmap_find (ecma_property_hashmap_t *hashmap_p, ecma_string_t *name_p,
76425bb815Sopenharmony_ci                                             jmem_cpointer_t *property_real_name_cp);
77425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_PROPRETY_HASHMAP) */
78425bb815Sopenharmony_ci
79425bb815Sopenharmony_ci/**
80425bb815Sopenharmony_ci * @}
81425bb815Sopenharmony_ci * @}
82425bb815Sopenharmony_ci */
83425bb815Sopenharmony_ci
84425bb815Sopenharmony_ci#endif /* !ECMA_PROPERTY_HASHMAP_H */
85