Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
6f695b8d
Commit
6f695b8d
authored
Aug 01, 2006
by
Warren Dukes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
a couple of small cleanups
git-svn-id:
https://svn.musicpd.org/mpd/trunk@4506
09075e82-0dd4-0310-85a5-a0d7c8717e4f
parent
c5cab165
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
49 deletions
+38
-49
tree.c
src/tree.c
+38
-49
No files found.
src/tree.c
View file @
6f695b8d
...
...
@@ -63,7 +63,7 @@ _MakeNode()
static
int
_FindPosition
InNode
(
Tree
*
tree
,
TreeNode
*
node
,
void
*
data
,
int
*
pos
)
_FindPosition
(
Tree
*
tree
,
TreeNode
*
node
,
void
*
data
,
int
*
pos
)
{
#ifdef USE_BINARY_SEARCH
int
low
=
0
;
...
...
@@ -109,10 +109,7 @@ _Find(TreeIterator * iter, void * data)
{
while
(
1
)
{
if
(
_FindPositionInNode
(
iter
->
tree
,
iter
->
node
,
data
,
&
iter
->
which
))
if
(
_FindPosition
(
iter
->
tree
,
iter
->
node
,
data
,
&
iter
->
which
))
{
return
1
;
}
...
...
@@ -195,7 +192,7 @@ _InsertNodeAndData(Tree * tree,
}
int
i
=
0
;
_FindPosition
InNode
(
tree
,
node
,
data
,
&
i
);
_FindPosition
(
tree
,
node
,
data
,
&
i
);
#ifdef USE_MEM_FUNC
memmove
(
&
(
node
->
data
[
i
+
1
]),
...
...
@@ -257,7 +254,7 @@ _AddDataToSplitNodes(Tree * tree,
}
int
i
=
0
;
_FindPosition
InNode
(
tree
,
moreNode
,
data
,
&
i
);
_FindPosition
(
tree
,
moreNode
,
data
,
&
i
);
if
(
i
==
0
)
{
...
...
@@ -382,30 +379,34 @@ void
_DeleteAt
(
TreeIterator
*
iter
)
{
TreeNode
*
node
=
iter
->
node
;
void
**
data
=
&
(
node
->
data
[
iter
->
which
]);
int
pos
=
iter
->
which
;
void
**
data
=
&
(
node
->
data
[
pos
]);
void
*
dataToFree
=
*
data
;
{
int
dir
=
0
;
TreeNode
*
child
=
NULL
;
// find the least greater than data to fill the whole!
if
(
node
->
children
[
iter
->
which
+
1
])
if
(
node
->
children
[
pos
+
1
])
{
dir
=
-
1
;
child
=
node
->
children
[
iter
->
which
+
1
];
}
// or the greatest lesser than data to fill the whole!
else
if
(
node
->
children
[
iter
->
which
])
child
=
node
->
children
[
++
pos
];
while
(
child
->
children
[
0
])
{
dir
=
1
;
child
=
node
->
children
[
iter
->
which
];
pos
=
0
;
child
=
child
->
children
[
0
];
}
if
(
dir
>
0
)
*
data
=
child
->
data
[
0
];
data
=
&
(
child
->
data
[
0
]);
node
=
child
;
}
// or the greatest lesser than data to fill the whole!
else
if
(
node
->
children
[
pos
])
{
child
=
node
->
children
[
pos
];
while
(
child
->
children
[
child
->
dataCount
])
{
pos
=
child
->
dataCount
;
child
=
child
->
children
[
child
->
dataCount
];
}
...
...
@@ -413,21 +414,17 @@ _DeleteAt(TreeIterator * iter)
data
=
&
(
child
->
data
[
child
->
dataCount
-
1
]);
node
=
child
;
}
else
if
(
dir
<
0
)
{
while
(
child
->
children
[
0
])
else
if
(
node
->
parent
)
{
child
=
child
->
children
[
0
];
}
*
data
=
child
->
data
[
0
];
data
=
&
(
child
->
data
[
0
]);
node
=
child
;
// if there are no children, we need to set _pos_
// to the correct node of the parent
_FindPosition
(
iter
->
tree
,
node
->
parent
,
node
->
data
[
0
],
&
pos
)
;
}
}
void
*
tempData
=
*
data
;
// move data nodes over, we're at a leaf node, so we can ignore
// children
int
i
=
--
node
->
dataCount
;
...
...
@@ -443,23 +440,10 @@ _DeleteAt(TreeIterator * iter)
// if we're not the root
if
(
node
->
parent
)
{
TreeNode
**
child
;
int
pos
;
// XXX : this find is unneccesary!
if
(
_FindPositionInNode
(
iter
->
tree
,
node
->
parent
,
tempData
,
&
pos
))
{
if
(
node
->
parent
->
children
[
pos
]
!=
node
)
{
pos
++
;
}
}
TreeNode
**
child
=
&
(
node
->
parent
->
children
[
pos
]);
assert
(
node
->
parent
->
children
[
pos
]
==
node
);
child
=
&
(
node
->
parent
->
children
[
pos
]);
// check siblings for
superfulous
data
// check siblings for
extra
data
if
(
pos
<
node
->
parent
->
dataCount
&&
(
*
(
child
+
1
))
->
dataCount
>
(
CHILDREN_PER_NODE
/
2
))
{
...
...
@@ -511,17 +495,16 @@ _DeleteAt(TreeIterator * iter)
NULL
;
(
*
child
)
->
data
[(
*
child
)
->
dataCount
]
=
NULL
;
}
// merge with one of our siblings
else
{
// merge with one of our siblings
if
(
pos
<
node
->
parent
->
dataCount
)
{
child
++
;
assert
(
*
child
);
tempData
=
node
->
parent
->
data
[
pos
];
node
->
data
[
node
->
dataCount
++
]
=
tempData
;
node
->
parent
->
data
[
pos
]
;
_MergeNodes
(
node
,
*
child
);
}
...
...
@@ -532,9 +515,8 @@ _DeleteAt(TreeIterator * iter)
assert
(
*
child
);
pos
--
;
tempData
=
node
->
parent
->
data
[
pos
];
(
*
child
)
->
data
[(
*
child
)
->
dataCount
++
]
=
tempData
;
node
->
parent
->
data
[
pos
]
;
_MergeNodes
(
*
child
,
node
);
node
=
*
child
;
...
...
@@ -552,6 +534,13 @@ _DeleteAt(TreeIterator * iter)
node
->
parent
->
children
[
i
+
1
]
=
NULL
;
node
->
parent
->
dataCount
--
;
if
(
node
->
parent
->
parent
)
{
_FindPosition
(
iter
->
tree
,
node
->
parent
->
parent
,
node
->
data
[
0
],
&
pos
);
}
node
=
node
->
parent
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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