Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

Commit 937037fd authored by rswindell's avatar rswindell

Added listCountMatches() - returns the number of linked-list nodes which match

the specified data (value or ptr) or tag value.
parent a1cd5bc5
/* link_list.c */
/* Double-Linked-list library */
/* $Id$ */
......@@ -8,7 +6,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2015 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
......@@ -313,6 +311,33 @@ list_node_t* DLLCALL listFindNode(link_list_t* list, const void* data, size_t le
return(node);
}
ulong DLLCALL listCountMatches(link_list_t* list, const void* data, size_t length)
{
list_node_t* node;
ulong matches = 0;
if(list==NULL)
return 0;
listLock(list);
for(node=list->first; node!=NULL; node=node->next) {
if(length==0) {
if(node->data!=data)
continue;
} else if(data==NULL) {
if(node->tag==(list_node_tag_t)length)
continue;
} else if(node->data==NULL || memcmp(node->data,data,length)!=0)
continue;
matches++;
}
listUnlock(list);
return matches;
}
str_list_t DLLCALL listStringList(link_list_t* list)
{
list_node_t* node;
......
/* link_list.h */
/* Double-Linked-list library */
/* $Id$ */
......@@ -8,7 +6,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2011 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
......@@ -143,11 +141,13 @@ DLLEXPORT link_list_t* DLLCALL listExtract(link_list_t* dest_list, const list_no
/* Simple search functions returning found node or NULL on error */
DLLEXPORT list_node_t* DLLCALL listNodeAt(link_list_t*, long index);
/* Find a specific node by data */
/* Find a specific node by data or tag */
/* Pass length of 0 to search by data pointer rather than by data content comparison (memcmp) */
DLLEXPORT list_node_t* DLLCALL listFindNode(link_list_t*, const void* data, size_t length);
/* Find a specific node by its tag value */
#define listFindTaggedNode(list, tag) listFindNode(list, NULL, tag)
/* Pass length of 0 to search by data pointer rather than by data content comparison (memcmp) */
DLLEXPORT ulong DLLCALL listCountMatches(link_list_t*, const void* data, size_t length);
/* Convenience functions */
DLLEXPORT list_node_t* DLLCALL listFirstNode(link_list_t*);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment