feat: rename core types to scc prefix for consistency
Updated type names from `core_*` to `scc_*` across lex_parser and stream modules to maintain naming consistency within the SCC codebase. This includes changes to function signatures and internal usage of types like `core_probe_stream_t`, `core_pos_t`, and `cstring_t` to their `scc_*` counterparts.
This commit is contained in:
@@ -5,8 +5,8 @@
|
||||
* 提供基于向量容器的哈希表实现,支持动态扩容和墓碑机制
|
||||
*/
|
||||
|
||||
#ifndef __SMCC_HASHMAP_H__
|
||||
#define __SMCC_HASHMAP_H__
|
||||
#ifndef __SCC_HASHMAP_H__
|
||||
#define __SCC_HASHMAP_H__
|
||||
|
||||
#include <libcore.h>
|
||||
|
||||
@@ -40,9 +40,9 @@ typedef struct hashmap_entry {
|
||||
* 使用开放寻址法实现,采用墓碑标记处理删除操作
|
||||
*/
|
||||
typedef struct smcc_hashmap {
|
||||
VEC(hashmap_entry_t) entries; /**< 条目存储容器 */
|
||||
u32 count; /**< 有效条目数量(不含墓碑) */
|
||||
u32 tombstone_count; /**< 墓碑条目数量 */
|
||||
SCC_VEC(hashmap_entry_t) entries; /**< 条目存储容器 */
|
||||
u32 count; /**< 有效条目数量(不含墓碑) */
|
||||
u32 tombstone_count; /**< 墓碑条目数量 */
|
||||
/**
|
||||
* @brief 哈希函数指针
|
||||
* @param key 键指针
|
||||
@@ -119,4 +119,4 @@ typedef int (*hashmap_iter_fn)(const void *key, void *value, void *context);
|
||||
*/
|
||||
void hashmap_foreach(hashmap_t *ht, hashmap_iter_fn iter_func, void *context);
|
||||
|
||||
#endif // __SMCC_HASHMAP_H__
|
||||
#endif /* __SCC_HASHMAP_H__ */
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
* 提供字符串驻留(String Interning)功能,保证相同字符串的唯一性存储
|
||||
*/
|
||||
|
||||
#ifndef __SMCC_STRPOOL_H__
|
||||
#define __SMCC_STRPOOL_H__
|
||||
#ifndef __SCC_STRPOOL_H__
|
||||
#define __SCC_STRPOOL_H__
|
||||
|
||||
#include "hashmap.h"
|
||||
#include <libcore.h>
|
||||
@@ -47,4 +47,4 @@ const char *strpool_intern(strpool_t *pool, const char *str);
|
||||
*/
|
||||
void strpool_destroy(strpool_t *pool);
|
||||
|
||||
#endif // __SMCC_STRPOOL_H__
|
||||
#endif /* __SCC_STRPOOL_H__ */
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#include <hashmap.h>
|
||||
|
||||
#ifndef SMCC_INIT_HASHMAP_SIZE
|
||||
#define SMCC_INIT_HASHMAP_SIZE (32)
|
||||
#ifndef SCC_INIT_HASHMAP_SIZE
|
||||
#define SCC_INIT_HASHMAP_SIZE (32)
|
||||
#endif
|
||||
|
||||
void hashmap_init(hashmap_t *ht) {
|
||||
vec_init(ht->entries);
|
||||
scc_vec_init(ht->entries);
|
||||
ht->count = 0;
|
||||
ht->tombstone_count = 0;
|
||||
Assert(ht->key_cmp != NULL && ht->hash_func != NULL);
|
||||
@@ -31,7 +31,7 @@ static hashmap_entry_t *find_entry(hashmap_t *ht, const void *key, u32 hash) {
|
||||
hashmap_entry_t *tombstone = NULL;
|
||||
|
||||
while (1) {
|
||||
hashmap_entry_t *entry = &vec_at(ht->entries, index);
|
||||
hashmap_entry_t *entry = &scc_vec_at(ht->entries, index);
|
||||
if (entry->state == ENTRY_EMPTY) {
|
||||
return tombstone ? tombstone : entry;
|
||||
}
|
||||
@@ -57,33 +57,33 @@ static void adjust_capacity(hashmap_t *ht, int new_cap) {
|
||||
new_cap = next_power_of_two(new_cap);
|
||||
Assert(new_cap >= ht->entries.cap);
|
||||
|
||||
VEC(hashmap_entry_t) old_entries;
|
||||
SCC_VEC(hashmap_entry_t) old_entries;
|
||||
old_entries.data = ht->entries.data;
|
||||
old_entries.cap = ht->entries.cap;
|
||||
|
||||
// Not used size but for gdb python extention debug
|
||||
ht->entries.size = new_cap;
|
||||
ht->entries.cap = new_cap;
|
||||
ht->entries.data = smcc_realloc(NULL, new_cap * sizeof(hashmap_entry_t));
|
||||
smcc_memset(ht->entries.data, 0, new_cap * sizeof(hashmap_entry_t));
|
||||
ht->entries.data = scc_realloc(NULL, new_cap * sizeof(hashmap_entry_t));
|
||||
scc_memset(ht->entries.data, 0, new_cap * sizeof(hashmap_entry_t));
|
||||
|
||||
// rehash the all of the old data
|
||||
for (usize i = 0; i < old_entries.cap; i++) {
|
||||
hashmap_entry_t *entry = &vec_at(old_entries, i);
|
||||
hashmap_entry_t *entry = &scc_vec_at(old_entries, i);
|
||||
if (entry->state == ENTRY_ACTIVE) {
|
||||
hashmap_entry_t *dest = find_entry(ht, entry->key, entry->hash);
|
||||
*dest = *entry;
|
||||
}
|
||||
}
|
||||
|
||||
vec_free(old_entries);
|
||||
scc_vec_free(old_entries);
|
||||
ht->tombstone_count = 0;
|
||||
}
|
||||
|
||||
void *hashmap_set(hashmap_t *ht, const void *key, void *value) {
|
||||
if (ht->count + ht->tombstone_count >= ht->entries.cap * 0.75) {
|
||||
int new_cap = ht->entries.cap < SMCC_INIT_HASHMAP_SIZE
|
||||
? SMCC_INIT_HASHMAP_SIZE
|
||||
int new_cap = ht->entries.cap < SCC_INIT_HASHMAP_SIZE
|
||||
? SCC_INIT_HASHMAP_SIZE
|
||||
: ht->entries.cap * 2;
|
||||
adjust_capacity(ht, new_cap);
|
||||
}
|
||||
@@ -134,14 +134,14 @@ void *hashmap_del(hashmap_t *ht, const void *key) {
|
||||
}
|
||||
|
||||
void hashmap_drop(hashmap_t *ht) {
|
||||
vec_free(ht->entries);
|
||||
scc_vec_free(ht->entries);
|
||||
ht->count = 0;
|
||||
ht->tombstone_count = 0;
|
||||
}
|
||||
|
||||
void hashmap_foreach(hashmap_t *ht, hashmap_iter_fn iter_func, void *context) {
|
||||
for (usize i = 0; i < ht->entries.cap; i++) {
|
||||
hashmap_entry_t *entry = &vec_at(ht->entries, i);
|
||||
hashmap_entry_t *entry = &scc_vec_at(ht->entries, i);
|
||||
if (entry->state == ENTRY_ACTIVE) {
|
||||
if (!iter_func(entry->key, entry->value, context)) {
|
||||
break; // enable callback function terminal the iter
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include "strpool.h"
|
||||
|
||||
void init_strpool(strpool_t *pool) {
|
||||
pool->ht.hash_func = (u32 (*)(const void *))smcc_strhash32;
|
||||
pool->ht.key_cmp = (int (*)(const void *, const void *))smcc_strcmp;
|
||||
pool->ht.hash_func = (u32 (*)(const void *))scc_strhash32;
|
||||
pool->ht.key_cmp = (int (*)(const void *, const void *))scc_strcmp;
|
||||
hashmap_init(&pool->ht);
|
||||
}
|
||||
|
||||
@@ -12,13 +12,13 @@ const char *strpool_intern(strpool_t *pool, const char *str) {
|
||||
return existing;
|
||||
}
|
||||
|
||||
usize len = smcc_strlen(str) + 1;
|
||||
char *new_str = smcc_malloc(len);
|
||||
usize len = scc_strlen(str) + 1;
|
||||
char *new_str = scc_malloc(len);
|
||||
if (!new_str) {
|
||||
LOG_ERROR("strpool: Failed to allocate memory for string");
|
||||
return NULL;
|
||||
}
|
||||
smcc_memcpy(new_str, str, len);
|
||||
scc_memcpy(new_str, str, len);
|
||||
|
||||
hashmap_set(&pool->ht, new_str, new_str);
|
||||
return new_str;
|
||||
|
||||
Reference in New Issue
Block a user