-
Notifications
You must be signed in to change notification settings - Fork 676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
literal storage: 4x performance improvement using a hashmap #5131
Open
ronanj
wants to merge
3
commits into
jerryscript-project:master
Choose a base branch
from
ronanj:lit-hashmap
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* Copyright JS Foundation and other contributors, http://js.foundation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/* | ||
The lit-hashmap library is based on the public domain software | ||
available from https://github.com/sheredom/hashmap.h | ||
*/ | ||
|
||
#ifndef LIT_HASHMAP_INTERNAL_H | ||
#define LIT_HASHMAP_INTERNAL_H | ||
|
||
#include "lit-hashmap.h" | ||
|
||
#define HASHMAP_ALWAYS_INLINE __attribute__ ((always_inline)) inline | ||
#define HASHMAP_LINEAR_PROBE_LENGTH (8) | ||
|
||
/** | ||
* hashmap creation options. | ||
*/ | ||
|
||
typedef struct hashmap_create_options_s | ||
{ | ||
hashmap_uint32_t initial_capacity; /**< initial hashmap capacity */ | ||
} hashmap_create_options_t; | ||
|
||
/// @brief Create a hashmap. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this type of comment is used in jerryscript |
||
/// @param options The options to create the hashmap with. | ||
/// @param out_hashmap The storage for the created hashmap. | ||
/// @return On success 0 is returned. | ||
/// | ||
/// The options members work as follows: | ||
/// - initial_capacity The initial capacity of the hashmap. | ||
/// - hasher Which hashing function to use with the hashmap (by default the | ||
// crc32 with Robert Jenkins' mix is used). | ||
int hashmap_create_ex (struct hashmap_create_options_s options, struct hashmap_s *const out_hashmap); | ||
|
||
/// @brief Iterate over all the elements in a hashmap. | ||
/// @param hashmap The hashmap to iterate over. | ||
/// @param iterator The function pointer to call on each element. | ||
/// @param context The context to pass as the first argument to f. | ||
/// @return If the entire hashmap was iterated then 0 is returned. | ||
/// Otherwise if the callback function f returned positive then the positive | ||
/// value is returned. If the callback function returns -1, the current item | ||
/// is removed and iteration continues. | ||
int hashmap_iterate_pairs (struct hashmap_s *const hashmap, | ||
int (*iterator) (void *const, struct hashmap_element_s *const), | ||
void *const context); | ||
|
||
/// @brief Get the size of the hashmap. | ||
/// @param hashmap The hashmap to get the size of. | ||
/// @return The size of the hashmap. | ||
HASHMAP_ALWAYS_INLINE hashmap_uint32_t hashmap_num_entries (const struct hashmap_s *const hashmap); | ||
|
||
/// @brief Get the capacity of the hashmap. | ||
/// @param hashmap The hashmap to get the size of. | ||
/// @return The capacity of the hashmap. | ||
HASHMAP_ALWAYS_INLINE hashmap_uint32_t hashmap_capacity (const struct hashmap_s *const hashmap); | ||
|
||
HASHMAP_ALWAYS_INLINE hashmap_uint32_t hashmap_hash_helper_int_helper (const struct hashmap_s *const m, | ||
const ecma_string_t *const key); | ||
HASHMAP_ALWAYS_INLINE int hashmap_hash_helper (const struct hashmap_s *const m, | ||
const ecma_string_t *const key, | ||
hashmap_uint32_t *const out_index); | ||
int hashmap_rehash_iterator (void *const new_hash, struct hashmap_element_s *const e); | ||
HASHMAP_ALWAYS_INLINE int hashmap_rehash_helper (struct hashmap_s *const m); | ||
HASHMAP_ALWAYS_INLINE hashmap_uint32_t hashmap_clz (const hashmap_uint32_t x); | ||
|
||
#endif // LIT_HASHMAP_INTERNAL_H |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The license of https://github.com/sheredom/hashmap.h, the "Unlincense" is problematic: https://groups.google.com/g/unlicense/c/G6pzAFtgrx0/m/9TCxE-je2qMJ
In general the Apache or MIT licenses are recommended instead of various "public domain" licenses such as this Unlicense or CC0.