Skip to content
Snippets Groups Projects
Commit 17107d6d authored by Oliver Sander's avatar Oliver Sander
Browse files

The items in an environment heap directory are stored in a list.

Previously, new items were appended to this list.  Since the end
of the list is not stored this was an O(n) procedure. This patch
changes the behavior such that new items are now inserted before
the first item.  Hence insertion is now O(1), which is very 
important to be able to read very large grids, because boundary
segments are stored in the environment tree.

Before inserting a new item the environment tree would also check whether
an item with the same name was already present.  This was also
an O(N) algorithm.  This check is now enabled only when 'Debug'
is set.



[[Imported from SVN: r8359]]
parent b37abfc9
No related branches found
No related tags found
No related merge requests found
......@@ -254,6 +254,8 @@ ENVITEM * NS_PREFIX MakeEnvItem (const char *name, const INT type, const INT siz
/* check if name not already used in this directory */
currentDir = path[pathIndex];
anItem = lastItem = currentDir->down;
#ifdef Debug
while (anItem!=NULL)
{
if ((anItem->v.type==type)&&(strcmp(anItem->v.name,name)==0))
......@@ -264,6 +266,7 @@ ENVITEM * NS_PREFIX MakeEnvItem (const char *name, const INT type, const INT siz
lastItem = anItem;
anItem = anItem->v.next;
}
#endif
/* allocate memory from environment heap */
switch (type)
......@@ -315,10 +318,11 @@ ENVITEM * NS_PREFIX MakeEnvItem (const char *name, const INT type, const INT siz
}
else
{
/* append to last Item */
lastItem->v.next = newItem;
newItem->v.previous = lastItem;
newItem->v.next = NULL;
/* insert before first item */
newItem->v.previous = NULL;
currentDir->down->v.previous = newItem;
newItem->v.next = currentDir->down;
currentDir->down = newItem;
}
/* return pointer to new item */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment