-
Notifications
You must be signed in to change notification settings - Fork 55
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
INTERNAL: Change tot_elem_cnt to subtree element count in set #817
base: develop
Are you sure you want to change the base?
Conversation
50d0a1d
to
dd999d1
Compare
dd999d1
to
6b2805e
Compare
6b2805e
to
8242e3a
Compare
8242e3a
to
2199b09
Compare
@@ -236,7 +236,7 @@ typedef struct _set_hash_node { | |||
uint16_t refcount; | |||
uint8_t slabs_clsid; /* which slab class we're in */ | |||
uint8_t hdepth; | |||
uint16_t tot_elem_cnt; | |||
uint32_t tot_elem_cnt; | |||
uint16_t tot_hash_cnt; | |||
int16_t hcnt[SET_HASHTAB_SIZE]; |
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.
@jeesup0103
ํ์ node๋ฅผ ๊ฐ์ง๋ ๊ฒฝ์ฐ์ hcnt[i] = -1
์ค์ ์ ๊ทธ๋๋ก ์ ์งํ๊ณ ์๋ค์.
๊ฐ hash bucket์ ์๋ element ๊ฐ์๋ hcnt[i] ๊ฐ์ ํ์ธํ ์ ์๊ณ ,
-1์ด๋ผ๋ฉด child node ์ ๊ทผํ์ฌ tot_elem_cnt ํ์ธํ๋ค๋ ๊ฒ์ด์ฃ .
hcnt[i]์์ ํ์ node์ ์๋ element ๊ฐ์๋ฅผ ์ ์งํ๋ ๋ฐฉ์๋ ์๊ฐํด ๋ณผ ์ ์๋ ๋ฐ,
์ด ๋ฐฉ์์ ํํ์ง ์์ ์ด์ ๋ ๋ฌด์์ธ๊ฐ์?
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.
@jhpark816
hcnt[hidx]
๊ฐ์ ๋ณ๊ฒฝํ์ง ์์ ์ด์ ๋ ํด๋น ๋ฒํท์ ์ํ๋ฅผ ๋ฐ๋ก ํ์ธํ ์ ์๋๋ก ์ ์งํ๊ธฐ ์ํด์์
๋๋ค.
DFS ํ์ ๊ณผ์ ์์ hcnt[hidx]
๋ฅผ ํตํด ํด๋น ๋ฒํท์ด ์ถ๊ฐ ๋
ธ๋์ธ์ง ๋๋ element chain์ธ์ง ๋น ๋ฅด๊ฒ ํ๋จํ ์ ์์ต๋๋ค.
๊ทธ๋ฆฌ๊ณ , hcnt[hidx]
๊ฐ๋ ํ์ ๋
ธ๋์ element ๊ฐ์๋ก ๋ณ๊ฒฝํ๋ค๋ฉด, ์ด๋ tot_elem_cnt
์ ์ค๋ณต ์ ๋ณด๋ฅผ ์ ์ฅํ๋ ํํ๊ฐ ๋ฉ๋๋ค.
๊ฒฐ๊ตญ, node->hcnt[hidx]
์ node->htab[hidx]->tot_elem_cnt
๋ ๊ฐ์ ๊ฐ์ ๊ฐ์ง๊ฒ ๋๊ธฐ ๋๋ฌธ์ tot_elem_cnt
๋ง ๋ณ๊ฒฝํ๋ ๊ฒ์ด ๋ ํจ์จ์ ์ด๋ผ๊ณ ์๊ฐํ์ต๋๋ค.
@namsic ์ถ๊ฐ ๋ฆฌ๋ทฐ ์งํํด ์ฃผ์ธ์. |
node->tot_elem_cnt += 1; | ||
node = info->root; | ||
while (node != NULL) { | ||
node->tot_elem_cnt += 1; |
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.
do_set_node_link()
, do_set_node_unlink()
, do_set_elem_link()
3๊ฐ ํจ์๋ ์์ ํ๋๋ฐ,
do_set_elem_unlink()
๋ ๊ธฐ์กด ๊ตฌํ์ ๊ทธ๋๋ก ์ฌ์ฉํ๊ณ ์์ต๋๋ค.
do_set_elem_traverse_XXX()
์์ ์ฒ๋ฆฌํ๊ธฐ ๋๋ฌธ์ธ๊ฐ์?- ๊ธฐ์กด ๊ตฌํ์์๋
XXX_link()
์XXX_unlink()
์์tot_elem_cnt
๊ฐ์ ๋ณ๊ฒฝํ๊ณ ,
traverse
ํจ์์์๋ ๋น๊ต ์ฐ์ฐ๋ง ์ํํ์ต๋๋ค.
๊ธฐ์กด์ฒ๋ผ ๋ฐ๋ ์ด๋ฆ์ ๊ฐ๋ ํจ์์ ๋์์ด ์๋ก ์ง์ ์ด๋ฃจ๋๋ก ๊ตฌํํ๊ธฐ๋ ์ด๋ ค์ด๊ฐ์?
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.
- ๋ค. ํด๋น ๋
ธ๋์ ๋ถ๋ชจ ๋
ธ๋๋ค์
tot_elem_cnt
๊ฐ์do_set_elem_traverse_XXX()
์์ ์ฒ๋ฆฌ ๋ฉ๋๋ค. - ์ด๋ ต์ง ์์ ๊ฒ ๊ฐ์ต๋๋ค.
do_set_elem_unlink()
์์do_set_elem_link()
์ ๊ฐ์ด ํด์๊ฐ์ ๊ธฐ์ค์ผ๋ก while๋ฌธ์ ๋ฐ๋ณตํด์ ๋ถ๋ชจ ๋ ธ๋๋ค์tot_elem_cnt
๊ฐ์ ์ ๋ฐ์ดํธ ํ ์ ์์ต๋๋ค.
๊ทธ๋ฌ๋ฉด ํ๋์ element๋ฅผ ์ญ์ ํ ๋๋ง๋ค ๋ถ๋ชจ ๋ ธ๋๋ค์ ์ ๋ฐ์ดํธ ํด์ผํ๋ ๋น์ฉ์ ๋ฐ์ํฉ๋๋ค. (ํ์ฌ PR์์๋ ๋ ธ๋๋น ํ๋ฒ ์ ๋ฐ์ดํธ)
while (node != NULL) {
node->tot_elem_cnt -= 1;
hidx = SET_GET_HASHIDX(elem->hval, node->hdepth);
if (node->hcnt[hidx] >= 0)
break;
node = node->htab[hidx];
}
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.
๋ฆฌ๋ทฐ ์๋ฃ
@@ -236,7 +236,7 @@ typedef struct _set_hash_node { | |||
uint16_t refcount; | |||
uint8_t slabs_clsid; /* which slab class we're in */ | |||
uint8_t hdepth; | |||
uint16_t tot_elem_cnt; | |||
uint32_t tot_elem_cnt; | |||
uint16_t tot_hash_cnt; |
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.
unit32_t tot_elem_cnt ๋ child node์ ์๋ elements ์๋ฅผ ํฌํจํ๋ ๊ฒ์ผ๋ก ๋ณ๊ฒฝํ๋ค๋ฉด,
uint16_t tot_hash_cnt ๋ ์ ๊ฑฐํ๋ ๊ฒ์ด ๋์ ๊ฒ ๊ฐ์ต๋๋ค. ๊ฒํ ํ ์กฐ์น ๋ฐ๋๋๋ค.
tot_hash_cnt๊ฐ ์ด์ฉ๋๋ 2๊ฐ์ง ๊ฒฝ์ฐ๊ฐ ์์ต๋๋ค.
์ฒซ์งธ, ์๋ ๊ฒฝ์ฐ์์ tot_elem_cnt == 0
์ด๋ฉด tot_hash_cnt == 0
์์ ์ ์ ์์ผ๋ฏ๋ก
tot_hash_cnt == 0
์กฐ๊ฑด์ ์ ๊ฑฐํด๋ ๋ฉ๋๋ค.
if (info->root->tot_hash_cnt == 0 && info->root->tot_elem_cnt == 0) {
do_set_node_unlink(info, NULL, 0);
}
๋์จฐ, ์๋ ๊ฒฝ์ฐ์์ tot_hash_cnt ํ๋๋ฅผ ์ ๊ฑฐํ๋ ๋์ ์
ํ์ํ๋ฉด get_child_node_count(node)
ํจ์๋ฅผ ๋์ด ๊ณ์ฐํ๊ฒ ์ฒ๋ฆฌํ ์ ์์ต๋๋ค.
if (child_node->tot_hash_cnt == 0 &&
child_node->tot_elem_cnt < (SET_MAX_HASHCHAIN_SIZE/2)) {
do_set_node_unlink(info, node, hidx);
}
=>
if (child_node->tot_elem_cnt < (SET_MAX_HASHCHAIN_SIZE/2)
&& get_child_node_count(node) == 0) {
do_set_node_unlink(info, node, hidx);
}
๊ทธ๋ฆฌ๊ณ tot_elem_cnt ํ๋๋ ๊ทธ ์๋ฏธ๊ฐ ๋ณ๊ฒฝ๋ ์ํ์ด๋ฏ๋ก,
ํ๋๋ช
์ ๋ค๋ฅด๊ฒ ๋ณ๊ฒฝํ ํ์๊ฐ ์๋์?
@@ -400,6 +404,7 @@ static ENGINE_ERROR_CODE do_set_elem_traverse_delete(set_meta_info *info, set_ha | |||
child_node->tot_elem_cnt < (SET_MAX_HASHCHAIN_SIZE/2)) { | |||
do_set_node_unlink(info, node, hidx); | |||
} | |||
node->tot_elem_cnt--; |
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.
์๋ ํํ๋ก ๋ณ๊ฒฝํ์์ฃ .
tot_elem_cnt ๋ณ๊ฒฝ ์คํ์ผ์ ๋์ผํ๊ฒ ๋ง์ถ๊ณ ์ ํฉ๋๋ค.
tot_elem_cnt -= 1;
if (node->hcnt[hidx] >= 0) | ||
break; | ||
node = node->htab[hidx]; | ||
} |
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.
delete ํ๋ ๊ฒฝ์ฐ์ ์ ์ฌํ๊ฒ
do_set_elem_traverse_insert()
๊ฐ์ ํจ์๋ก ์ฌ๊ท์ ์ผ๋ก child node๋ฅผ ์ฐพ์๊ฐ์
linkํ๋ ๊ตฌํ์ ์๊ฐํด ๋ณผ ์ ์์ ๊ฒ์
๋๋ค.
์ด๋ ๊ฒ ๊ตฌํํ ํ์๋ ์๊ฒ ์ฃ ?
๐ Related Issue
โจ๏ธ What I did
tot_elem_cnt
๋ฅผ ํด๋น ๋ ธ๋์ subtree์ ํฌํจ๋ ๋ชจ๋ element์ ์ด ๊ฐ์๋ก ๋ณ๊ฒฝ์ธ๋ถ ๊ตฌํ ๋ด์ฉ
tot_elem_cnt
ํฌ๊ธฐ ํ์ฅuint16_t
์์uint32_t
๋ก ๋ณ๊ฒฝtot_elem_cnt
๋ณ์ ๊ด๋ฆฌElement Insert (
do_set_elem_link()
)tot_elem_cnt
๋ฅผ 1 ์ฆ๊ฐElement Delete (
do_set_elem_traverse_dfs()
,do_set_elem_traverse_delete()
)tot_elem_cnt
๋ฅผ 1 ๊ฐ์Chain -> Hash table ๋ณ๊ฒฝ (
do_set_node_link()
)tot_elem_cnt
์ ์งtot_elem_cnt
= ๊ธฐ์กด Chain element ๊ฐ์ (num_found)Hash table -> Chain (
do_set_node_unlink()
)tot_elem_cnt
์ ์งtot_elem_cnt
= 0์ถํ PR ๋ด์ฉ