-
Notifications
You must be signed in to change notification settings - Fork 99
Use uint32_t instead of size_t where possible
#110
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,17 +40,17 @@ class Keyset { | |
| return key_blocks_[i / KEY_BLOCK_SIZE][i % KEY_BLOCK_SIZE]; | ||
| } | ||
|
|
||
| std::size_t num_keys() const { | ||
| uint32_t num_keys() const { | ||
| return size_; | ||
| } | ||
|
|
||
| bool empty() const { | ||
| return size_ == 0; | ||
| } | ||
| std::size_t size() const { | ||
| uint32_t size() const { | ||
| return size_; | ||
| } | ||
| std::size_t total_length() const { | ||
| uint32_t total_length() const { | ||
| return total_length_; | ||
| } | ||
|
|
||
|
|
@@ -61,23 +61,23 @@ class Keyset { | |
|
|
||
| private: | ||
| std::unique_ptr<std::unique_ptr<char[]>[]> base_blocks_; | ||
| std::size_t base_blocks_size_ = 0; | ||
| std::size_t base_blocks_capacity_ = 0; | ||
| uint32_t base_blocks_size_ = 0; | ||
| uint32_t base_blocks_capacity_ = 0; | ||
| std::unique_ptr<std::unique_ptr<char[]>[]> extra_blocks_; | ||
| std::size_t extra_blocks_size_ = 0; | ||
| std::size_t extra_blocks_capacity_ = 0; | ||
| uint32_t extra_blocks_size_ = 0; | ||
| uint32_t extra_blocks_capacity_ = 0; | ||
| std::unique_ptr<std::unique_ptr<Key[]>[]> key_blocks_; | ||
| std::size_t key_blocks_size_ = 0; | ||
| std::size_t key_blocks_capacity_ = 0; | ||
| uint32_t key_blocks_size_ = 0; | ||
| uint32_t key_blocks_capacity_ = 0; | ||
|
Comment on lines
+64
to
+71
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. While these should fit in a uint32_t, it might be better to keep this as a size_t since they're primarily used for indexing memory. |
||
| char *ptr_ = nullptr; | ||
| std::size_t avail_ = 0; | ||
| std::size_t size_ = 0; | ||
| std::size_t total_length_ = 0; | ||
| uint32_t avail_ = 0; | ||
| uint32_t size_ = 0; | ||
| uint32_t total_length_ = 0; | ||
|
|
||
| char *reserve(std::size_t size); | ||
| char *reserve(uint32_t size); | ||
|
|
||
| void append_base_block(); | ||
| void append_extra_block(std::size_t size); | ||
| void append_extra_block(uint32_t size); | ||
| void append_key_block(); | ||
| }; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,7 +37,7 @@ class Query { | |
| ptr_ = ptr; | ||
| length_ = length; | ||
| } | ||
| void set_id(std::size_t id) { | ||
| void set_id(uint32_t id) { | ||
| id_ = id; | ||
| } | ||
|
|
||
|
|
@@ -47,10 +47,10 @@ class Query { | |
| const char *ptr() const { | ||
| return ptr_; | ||
| } | ||
| std::size_t length() const { | ||
| uint32_t length() const { | ||
| return length_; | ||
|
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. Add an |
||
| } | ||
| std::size_t id() const { | ||
| uint32_t id() const { | ||
| return id_; | ||
| } | ||
|
|
||
|
|
@@ -65,8 +65,8 @@ class Query { | |
|
|
||
| private: | ||
| const char *ptr_ = nullptr; | ||
| std::size_t length_ = 0; | ||
| std::size_t id_ = 0; | ||
| uint32_t length_ = 0; | ||
| uint32_t id_ = 0; | ||
| }; | ||
|
|
||
| } // namespace marisa | ||
|
|
||
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 setter on line 41 is
void set_id(std::size_t id), but should probably also be a uint32_t.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.
Also,
#include <cstdint>should probably be added to this file.