Compiler version - TI v18.12.1.LTS
CCS - 9.0.1.00004
Is map implemented in TI complier as red-black tree?
if element is being added/deleted into a map, does find() guarantee correct operation if perform simultaneously?
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Compiler version - TI v18.12.1.LTS
CCS - 9.0.1.00004
Is map implemented in TI complier as red-black tree?
if element is being added/deleted into a map, does find() guarantee correct operation if perform simultaneously?
Is map implemented in TI complier as red-black tree?
Yes
if element is being added/deleted into a map, does find() guarantee correct operation if perform simultaneously?
I presume you have two different threads of execution accessing the same map container. I think the answer is no. But I'll get back to you on that.
Thanks and regards,
-George
if element is being added/deleted into a map, does find() guarantee correct operation if perform simultaneously?
I can confirm that the answer is no.
Thanks and regards,
-George
Hello George,
Thank you for response; as par my understanding, an insert operation to map will not modify memory location of existing elements. I think delete can cause the modification. So insert and find operation can perform simultaneously. Can you please confirm this?
This ...
an insert operation to map will not modify memory location of existing elements.
... is incorrect. A red-black tree is a variant of a balanced binary tree. This means, when an element is inserted, it is possible the tree gets rebalanced. While it is true that none of the existing elements change locations, the pointers inside those element do change. The find operation relies on those same pointers. I'm not sure what happens if a find and tree rebalance run at the same time. It can't be good.
Thanks and regards,
-George
Thank you for explanation; I did not clearly understand your below statement; I will deep dive further. Thank you.
the pointers inside those element do chang
The elements in the red-black tree contain fields that are pointers. They have names similar to left and right. They each point to one element of a red-black tree. An insert operation may cause a tree to be rebalanced. If so, some of these left and right fields in the elements change value. A find operation uses the left and right fields to navigate through the tree. If both operations occur at once, bad things are likely to happen.
Thanks and regards,
-George