Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
emulab
emulabdevel
Commits
fdaf8f62
Commit
fdaf8f62
authored
Feb 15, 2005
by
Siddharth Aggarwal
Browse files
With jon's bug fix for corner case where multiple inserts of different
sizes at the same starting block
parent
3b69e3c4
Changes
1
Hide whitespace changes
Inline
Sidebyside
os/shd/trie.c
View file @
fdaf8f62
...
...
@@ 106,7 +106,7 @@ int TrieInit(Trie ** trieOutPtr, BlockAllocateFunction blockAlloc,
result
=
1
;
if
(
trie
==
0
)
{
printf
(
"Error
doing TrieInit! Not enough memory!
\n
"
);
printf
(
"Error
allocating memory for TrieInit
\n
"
);
result
=
0
;
}
else
...
...
@@ 316,7 +316,43 @@ static int insertWeak(Trie * triePtr, TrieNode * node, TrieKey key,
while
(
!
done
)
{
node
=
search
(
node
,
key
,
maxDepth
);
if
(
isBranch
(
node
))
if
(
node
>
depth
==
node
>
maxDepth
&&
isLeaf
(
node
))
{
/* The current node is larger than our insertion.
Nothing to do. */
total
=
0
;
done
=
1
;
}
else
if
(
node
>
depth
==
maxDepth
)
{
/* We don't want to go below this level.
We are weak, so we have to break up the range
and insert smaller blocks */
/* There are two possibilities at this point. Either the
node is a leaf and we are a superset of a single
range. Or the node is a branch and there are many
possible subranges which are being used. */
if
(
isLeaf
(
node
))
{
/* The node is a leaf, so we have a single range to
work around. */
total
=
weakOverlap
(
triePtr
,
node
,
key
,
maxDepth
);
}
else
{
/* The node is a branch, so there are many ranges to
work around. The easiest way to solve this is to
split the problem in two and try to
reinsert. Eventually, this should resolve itself
to the other cases as we recurse. */
insertWeak
(
triePtr
,
node
,
key
,
maxDepth
+
1
);
insertWeak
(
triePtr
,
node
,
key
+
depthToSize
(
maxDepth
+
1
),
maxDepth
+
1
);
}
done
=
1
;
}
else
if
(
isBranch
(
node
))
{
/* If the node is a branch, we just insert ourselves. */
TrieValue
value
=
(
triePtr
>
blockAlloc
)(
depthToSize
(
maxDepth
));
...
...
@@ 333,21 +369,6 @@ static int insertWeak(Trie * triePtr, TrieNode * node, TrieKey key,
}
done
=
1
;
}
else
if
(
node
>
depth
==
node
>
maxDepth
)
{
/* The current node is larger than our insertion.
Nothing to do. */
total
=
0
;
done
=
1
;
}
else
if
(
node
>
depth
==
maxDepth
)
{
/* We don't want to go below this level.
We are weak, so we have to break up the range
and insert smaller blocks */
total
=
weakOverlap
(
triePtr
,
node
,
key
,
maxDepth
);
done
=
1
;
}
else
{
/* The current node is a leaf. Push it down to the next level. */
...
...
@@ 369,13 +390,7 @@ static int insertStrong(Trie * triePtr, TrieNode * node, TrieKey key,
while
(
!
done
)
{
node
=
search
(
node
,
key
,
maxDepth
);
if
(
isBranch
(
node
))
{
/* If the node is a branch, we just insert ourselves. */
total
=
addChild
(
triePtr
,
node
,
key
,
maxDepth
,
value
);
done
=
1
;
}
else
if
(
node
>
depth
==
maxDepth
)
if
(
node
>
depth
==
maxDepth
)
{
/* We don't want to go below this level.
We are strong, just replace whatever is here because
...
...
@@ 383,6 +398,12 @@ static int insertStrong(Trie * triePtr, TrieNode * node, TrieKey key,
total
=
replace
(
triePtr
,
node
,
key
,
maxDepth
,
value
,
overlap
);
done
=
1
;
}
else
if
(
isBranch
(
node
))
{
/* If the node is a branch, we just insert ourselves. */
total
=
addChild
(
triePtr
,
node
,
key
,
maxDepth
,
value
);
done
=
1
;
}
else
if
(
node
>
depth
==
node
>
maxDepth
)
{
/* If the target node is already at its lowest level
...
...
@@ 425,7 +446,7 @@ static int addChild(Trie * triePtr, TrieNode * parent, TrieKey key,
}
else
{
printf
(
"Error
doing addChild for Trie! Not enough memory!
\n
"
);
printf
(
"Error
allocating memory for addChild
\n
"
);
result
=

1
;
}
return
result
;
...
...
@@ 476,6 +497,7 @@ static void freeChildren(Trie * triePtr, TrieNode * node, OverlapT overlap)
,
M_DEVBUF
#endif
);
node
>
child
[
i
]
=
0
;
}
}
}
...
...
@@ 579,7 +601,7 @@ static TrieNode * pushDown(Trie * triePtr, TrieNode * node)
}
else
{
printf
(
"Error
doing pushDown for Trie! Not enough memory!
\n
"
);
printf
(
"Error
allocating memory for pushDown
\n
"
);
middle
=
0
;
}
return
middle
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment