|
About ::
TODO ::
Blog ::
RSS ::
Old blog ::
Projects ::
GIT ::
Gallery ::
Notes
Tue, 14 Nov 2006
Why trees are better than binary search.
if (in->min < new->min) {
netchannel_interval_split(in, in->min, new->min-1, GFP_KERNEL);
if (in->max > new->max) {
netchannel_interval_split(NULL, new->min, new->max, GFP_KERNEL);
netchannel_interval_split(new, new->max+1, in->max, GFP_KERNEL);
} else if (in->max < new->max) {
netchannel_interval_split(NULL, new->min, in->max, GFP_KERNEL);
netchannel_interval_split(new, in->max+1, new->max, GFP_KERNEL);
} else {
netchannel_interval_split(new, new->min, in->max, GFP_KERNEL);
}
} else if (in->min > new->min) {
netchannel_interval_split(in, new->min, in->min-1, GFP_KERNEL);
if (in->max > new->max) {
netchannel_interval_split(NULL, in->min, new->max, GFP_KERNEL);
netchannel_interval_split(new, new->max+1, in->max, GFP_KERNEL);
} else if (in->max < new->max) {
netchannel_interval_split(NULL, in->min, in->max, GFP_KERNEL);
netchannel_interval_split(new, in->max+1, new->max, GFP_KERNEL);
} else {
netchannel_interval_split(new, in->min, new->max, GFP_KERNEL);
}
} else {
if (in->max > new->max) {
netchannel_interval_split(in, in->min, new->max, GFP_KERNEL);
netchannel_interval_split(new, new->max+1, in->max, GFP_KERNEL);
} else if (in->max < new->max) {
netchannel_interval_split(in, in->min, in->max, GFP_KERNEL);
netchannel_interval_split(new, in->max+1, new->max, GFP_KERNEL);
} else {
netchannel_interval_split(in, in->min, in->max, GFP_KERNEL);
}
}
I think my head will be broken in a couple of moments...Tricky algorithm should be used there probably to split them up, but I currently fail to research one, so I use stupid but the fastest - there are only two checks and one allocation (or two if new interval was allocated in stack) for the worst case of crossing, when two crossed intervals are put into three non-crossing ones. /devel/networking :: Link / Comments () |