Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Synchronet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Main
Synchronet
Commits
766475db
Commit
766475db
authored
20 years ago
by
rswindell
Browse files
Options
Downloads
Patches
Plain Diff
Added functions for merging and extracting lists of nodes.
parent
9f47569a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/xpdev/link_list.c
+83
-11
83 additions, 11 deletions
src/xpdev/link_list.c
src/xpdev/link_list.h
+14
-0
14 additions, 0 deletions
src/xpdev/link_list.h
with
97 additions
and
11 deletions
src/xpdev/link_list.c
+
83
−
11
View file @
766475db
...
...
@@ -249,19 +249,11 @@ void* listNodeData(const list_node_t* node)
return
(
node
->
data
);
}
list_node_t
*
list
AddN
ode
(
link_list_t
*
list
,
void
*
data
,
list_node_t
*
after
)
static
list_node_t
*
list
_add_n
ode
(
link_list_t
*
list
,
list_node_t
*
node
,
list_node_t
*
after
)
{
list_node_t
*
node
;
if
(
list
==
NULL
)
return
(
NULL
);
if
((
node
=
(
list_node_t
*
)
malloc
(
sizeof
(
list_node_t
)))
==
NULL
)
return
(
NULL
);
memset
(
node
,
0
,
sizeof
(
list_node_t
));
node
->
data
=
data
;
node
->
prev
=
after
;
if
(
after
==
list
->
last
)
/* append to list */
...
...
@@ -284,6 +276,34 @@ list_node_t* listAddNode(link_list_t* list, void* data, list_node_t* after)
return
(
node
);
}
list_node_t
*
listAddNode
(
link_list_t
*
list
,
void
*
data
,
list_node_t
*
after
)
{
list_node_t
*
node
;
if
(
list
==
NULL
)
return
(
NULL
);
if
((
node
=
(
list_node_t
*
)
malloc
(
sizeof
(
list_node_t
)))
==
NULL
)
return
(
NULL
);
return
(
list_add_node
(
list
,
node
,
after
));
}
list_node_t
*
listAddNodes
(
link_list_t
*
list
,
void
**
data
,
list_node_t
*
after
)
{
size_t
i
;
list_node_t
*
node
=
NULL
;
if
(
data
==
NULL
)
return
(
NULL
);
for
(
i
=
0
;
data
[
i
];
i
++
)
if
((
node
=
listAddNode
(
list
,
data
[
i
],
node
==
NULL
?
after
:
node
))
==
NULL
)
return
(
NULL
);
return
(
node
);
}
list_node_t
*
listAddNodeData
(
link_list_t
*
list
,
const
void
*
data
,
size_t
length
,
list_node_t
*
after
)
{
list_node_t
*
node
;
...
...
@@ -326,20 +346,72 @@ list_node_t* listAddNodeString(link_list_t* list, const char* str, list_node_t*
return
(
node
);
}
list_node_t
*
listAddStringList
(
link_list_t
*
list
,
str_list_t
str_list
,
list_node_t
*
node
)
list_node_t
*
listAddStringList
(
link_list_t
*
list
,
str_list_t
str_list
,
list_node_t
*
after
)
{
size_t
i
;
list_node_t
*
node
=
NULL
;
if
(
str_list
==
NULL
)
return
(
NULL
);
for
(
i
=
0
;
str_list
[
i
];
i
++
)
if
((
node
=
listAddNodeString
(
list
,
str_list
[
i
],
node
))
==
NULL
)
if
((
node
=
listAddNodeString
(
list
,
str_list
[
i
],
node
==
NULL
?
after
:
node
))
==
NULL
)
return
(
NULL
);
return
(
node
);
}
list_node_t
*
listAddNodeList
(
link_list_t
*
list
,
const
link_list_t
*
src
,
list_node_t
*
after
)
{
list_node_t
*
node
=
NULL
;
list_node_t
*
src_node
;
if
(
src
==
NULL
)
return
(
NULL
);
for
(
src_node
=
src
->
first
;
src_node
!=
NULL
;
src_node
=
src_node
->
next
)
{
if
((
node
=
listAddNode
(
list
,
src_node
->
data
,
node
==
NULL
?
after
:
node
))
==
NULL
)
return
(
NULL
);
node
->
flags
=
src_node
->
flags
;
}
return
(
node
);
}
list_node_t
*
listMerge
(
link_list_t
*
list
,
const
link_list_t
*
src
,
list_node_t
*
after
)
{
list_node_t
*
node
=
NULL
;
list_node_t
*
src_node
;
if
(
src
==
NULL
)
return
(
NULL
);
for
(
src_node
=
src
->
first
;
src_node
!=
NULL
;
src_node
=
src_node
->
next
)
if
((
node
=
list_add_node
(
list
,
src_node
,
node
==
NULL
?
after
:
node
))
==
NULL
)
return
(
NULL
);
return
(
node
);
}
link_list_t
*
listExtract
(
link_list_t
*
dest_list
,
const
list_node_t
*
node
,
long
max
)
{
long
count
=
0
;
link_list_t
*
list
;
if
(
node
==
NULL
)
return
(
NULL
);
if
((
list
=
listInit
(
dest_list
))
==
NULL
)
return
(
NULL
);
for
(
count
=
0
;
count
<
max
&&
node
!=
NULL
;
node
=
node
->
next
)
{
listAddNode
(
list
,
node
->
data
,
list
->
last
);
count
++
;
}
return
(
list
);
}
void
*
listRemoveNode
(
link_list_t
*
list
,
list_node_t
*
node
)
{
void
*
data
;
...
...
This diff is collapsed.
Click to expand it.
src/xpdev/link_list.h
+
14
−
0
View file @
766475db
...
...
@@ -79,6 +79,10 @@ str_list_t listStringList(const link_list_t*);
/* Return an allocated string list (which must be freed), subset of strings in linked list */
str_list_t
listSubStringList
(
const
list_node_t
*
,
long
max
);
/* Extract subset (up to max number of nodes) in linked list (src_node) and place into dest_list */
/* dest_list == NULL, then allocate a return a new linked list */
link_list_t
*
listExtract
(
link_list_t
*
dest_list
,
const
list_node_t
*
src_node
,
long
max
);
/* Simple search functions returning found node or NULL on error */
list_node_t
*
listNodeAt
(
const
link_list_t
*
,
long
index
);
list_node_t
*
listFindNode
(
const
link_list_t
*
,
void
*
data
,
size_t
length
);
...
...
@@ -93,6 +97,9 @@ void* listNodeData(const list_node_t*);
/* Add node to list, returns pointer to new node or NULL on error */
list_node_t
*
listAddNode
(
link_list_t
*
,
void
*
data
,
list_node_t
*
after
/* NULL=insert */
);
/* Add array of node data to list, returns pointer to last new node or NULL on error */
list_node_t
*
listAddNodes
(
link_list_t
*
,
void
**
data
,
list_node_t
*
after
/* NULL=insert */
);
/* Add node to list, allocating and copying the data for the node */
list_node_t
*
listAddNodeData
(
link_list_t
*
,
const
void
*
data
,
size_t
length
,
list_node_t
*
after
);
...
...
@@ -102,6 +109,13 @@ list_node_t* listAddNodeString(link_list_t*, const char* str, list_node_t* after
/* Add a list of strings to the linked list, allocating and copying each */
list_node_t
*
listAddStringList
(
link_list_t
*
,
str_list_t
,
list_node_t
*
after
);
/* Add a list of nodes from a source linked list */
list_node_t
*
listAddNodeList
(
link_list_t
*
,
const
link_list_t
*
src
,
list_node_t
*
after
);
/* Merge a source linked list into the destination linked list */
/* after merging, the nodes in the source linked list should not be modified or freed */
list_node_t
*
listMerge
(
link_list_t
*
dest
,
const
link_list_t
*
src
,
list_node_t
*
after
);
/* Convenience macros for pushing, popping, and inserting nodes */
#define listPushNode(list, data) listAddNode(list, data, listLastNode(list))
#define listInsertNode(link, data) listAddNode(list, data, NULL)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment