[GSoC]use hash/map in POSIX key and Classic notepad

Gedare Bloom gedare at rtems.org
Thu Apr 5 16:09:14 UTC 2012


On Thu, Apr 5, 2012 at 10:44 AM, 阿四 <ashi08104 at gmail.com> wrote:
>
>
>> > And another idea of hash + map, if the map part is a sub rbtree, then
>> > the
>> > size of hash table can be not too big, the search operation could
>> > benifit
>> > from the rbtree's O(lg(n)) speed, could it be a candidate of the
>> > solution?
>> You mean to use a hash-array with an rbtree to handle collisions?
>
> Yeah, I mean it.
>>
>> It
>> could work, and be faster on average than just using an rbtree without
>> losing any worst-case time. The space overhead might be quite a bit
>> more to have multiple rbtree control headers and also the extra
>> overhead of rbtree nodes. I think that any rbtree- or chain-based
>> approach shifts the problem of determining the number of Keys to be
>> the problem of determining the number of nodes, since we cannot assume
>> that the Key data has a node embedded inside of it.
>>
> Gedare, I didn't quite understand this. Does rbtree approach has the problem
> of determining the number of nodes? I think when the key_create() function
> called, only a empty rbtree create. And when key_setspecific() function
> called, a node is added to rbtree. Or you mean create a 'proper' big rbtree
> when key_create(), which frontloads the insert node cost to key_create() as
> you mention above? I understand when using the hash approach, determing the
> number of slots(I'm confused with the Keys you use here, I guess Keys here
> is the slots in hash table) of hash table is the problem of determining the
> number of nodes.
>
It depends on the restrictions on key_create and key_setspecific; if
creation is allowed to block/fail then dynamic allocation might be ok.
I haven't looked closely enough to tell. In that case you can create
an rbtree on-the-fly by allocating it when there is a collision and
inserting the colliding nodes to it. You could also just as easily use
a linked-list (chain). The colliding nodes will need to be embedded
inside some other structure like
struct {
  RBTree_Node r; // or Chain_Node
  void * user_data;
}

this structure would have to be allocated as well whenever inserting a
new key (setspecific).  We need to better define the restrictions on
the keys in order to understand what kind of solutions we can use.
Restrictions means timing and memory constraints, whether operations
can block..maybe others.

>> I don't see why we don't just put a pointer to the Key in the tcb.
>
> Does it mean delete the POSIX Key data structure, and let the Thread
> Specific Data be managed in TCB?
Yeah. We could define generic thread-specific data at the score level.
I'm not sure if this is a good idea.

-Gedare




More information about the devel mailing list