* [1/2] find ptr in a list
@ 2008-09-04 5:34 Christopher Li
0 siblings, 0 replies; only message in thread
From: Christopher Li @ 2008-09-04 5:34 UTC (permalink / raw)
To: Linux-Sparse, Alexey Zaytsev, Josh Triplett
[-- Attachment #1: Type: text/plain, Size: 51 bytes --]
Signed-Off-By: Christopher Li <sparse@chrisli.org>
[-- Attachment #2: find-ptr-in-list --]
[-- Type: application/octet-stream, Size: 1197 bytes --]
Adding some helper function to find a pointer in the ptrlist.
Index: sparse/ptrlist.h
===================================================================
--- sparse.orig/ptrlist.h
+++ sparse/ptrlist.h
@@ -45,6 +45,8 @@ extern void concat_ptr_list(struct ptr_l
extern void __free_ptr_list(struct ptr_list **);
extern int ptr_list_size(struct ptr_list *);
extern int linearize_ptr_list(struct ptr_list *, void **, int);
+extern int find_ptr_in_list(struct ptr_list* list, void *ptr);
+extern int find_ptr_index(struct ptr_list* list, void *ptr);
/*
* Hey, who said that you can't do overloading in C?
Index: sparse/ptrlist.c
===================================================================
--- sparse.orig/ptrlist.c
+++ sparse/ptrlist.c
@@ -246,3 +246,29 @@ void __free_ptr_list(struct ptr_list **l
*listp = NULL;
}
+
+int find_ptr_in_list(struct ptr_list* list, void *ptr)
+{
+ void *p;
+ FOR_EACH_PTR(list, p) {
+ if (p == ptr)
+ return 1;
+ } END_FOR_EACH_PTR(p);
+ return 0;
+}
+
+int find_ptr_index(struct ptr_list* list, void *ptr)
+{
+ void *p;
+ int i = 0;
+ FOR_EACH_PTR(list, p) {
+ if (p == ptr)
+ return i;
+ i++;
+ } END_FOR_EACH_PTR(p);
+ return -1;
+}
+
+
+
+
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2008-09-04 5:34 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-04 5:34 [1/2] find ptr in a list Christopher Li
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).