}
}
-void
-SGPropertyNode::hash_table::bucket::erase (const char * key)
-{
- int i;
- for (i = 0; i < _length; i++) {
- if (!strcmp(_entries[i]->get_key(), key))
- break;
- }
-
- if (i < _length) {
- delete _entries[i];
- for (++i; i < _length; i++) {
- _entries[i-1] = _entries[i];
- }
- _length--;
- }
-}
-
bool
SGPropertyNode::hash_table::bucket::erase (SGPropertyNode * node)
{
return false;
}
+void
+SGPropertyNode::hash_table::bucket::clear (SGPropertyNode::hash_table * owner)
+{
+ for (int i = 0; i < _length; i++) {
+ SGPropertyNode * node = _entries[i]->get_value();
+ if (node)
+ node->remove_linked_node(owner);
+ }
+}
+
SGPropertyNode::hash_table::hash_table ()
: _data_length(0),
_data(0)
SGPropertyNode::hash_table::~hash_table ()
{
- for (unsigned int i = 0; i < _data_length; i++)
- delete _data[i];
+ for (unsigned int i = 0; i < _data_length; i++) {
+ if (_data[i]) {
+ _data[i]->clear(this);
+ delete _data[i];
+ }
+ }
delete [] _data;
}
value->add_linked_node(this);
}
-void
-SGPropertyNode::hash_table::erase (const char * key)
-{
- if (_data_length == 0)
- return;
- unsigned int index = hashcode(key) % _data_length;
- if (_data[index] == 0)
- return;
- _data[index]->erase(key);
-}
-
bool
SGPropertyNode::hash_table::erase (SGPropertyNode * node)
{
bucket ();
~bucket ();
entry * get_entry (const char * key, bool create = false);
- void erase (const char * key);
bool erase (SGPropertyNode * node);
+ void clear (hash_table * owner);
private:
int _length;
entry ** _entries;
~hash_table ();
SGPropertyNode * get (const char * key);
void put (const char * key, SGPropertyNode * value);
- void erase (const char * key);
bool erase (SGPropertyNode * node);
private: