Skip to content
Snippets Groups Projects
Commit fb8b51cb authored by Jakob Olsson's avatar Jakob Olsson
Browse files

preparation for dfs algorithm

parent 9400fff6
No related branches found
No related tags found
No related merge requests found
dfs.c 0 → 100644
/*
DFS(G,v) ( v is the vertex where the search starts )
Stack S := {}; ( start with an empty stack )
for each vertex u, set visited[u] := false;
push S, v;
while (S is not empty) do
u := pop S;
if (not visited[u]) then
visited[u] := true;
for each unvisited neighbour w of u
push S, w;
end if
end while
END DFS()
*/
#include "dfs.h"
void stack_enqueue(struct node *n, struct list_head *stack)
{
if (list_empty(stack))
INIT_LIST_HEAD(stack);
list_add(&node->list, stack);
}
struct node *stack_dequeue(struct list_head *stack)
{
struct node *n;
return list_first_entry(stack, struct node, list);
}
void add_visited(struct node *n, struct list_head *visited)
{
if (list_empty(visited))
INIT_LIST_HEAD(visited);
list_add(&node->list, visited);
}
bool is_visited(struct node *n, struct list_head *visited)
{
struct node *tmp;
list_for_each_entry(tmp, visited, list) {
if (strncmp(tmp->path, n->path, 1024) == 0)
return true;
}
return false;
}
\ No newline at end of file
dfs.h 0 → 100644
#ifndef DFS_H
#define DFS_H
#include "common.h"
struct node {
struct list_head list;
char *path;
char *name;
};
void enqueue_stack(struct node *n, struct list_head *stack);
struct node *dequeue_stack(struct list_head *stack);
void add_visited(struct node *n, struct list_head *visited);
bool is_visited(struct node *n, struct list_head *visited);
#endif
\ No newline at end of file
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "dongle_infrastructure.h" #include "dongle_infrastructure.h"
#include "dongle.h" #include "dongle.h"
#include "dfs.h"
enum { enum {
DEV, DEV,
...@@ -28,6 +29,8 @@ const struct blobmsg_policy dev_policy[__DEV_MAX] = { ...@@ -28,6 +29,8 @@ const struct blobmsg_policy dev_policy[__DEV_MAX] = {
}; };
LIST_HEAD(devices); LIST_HEAD(devices);
LIST_HEAD(visited);
LIST_HEAD(unvisited);
int devices_status(struct uloop_timeout *t) int devices_status(struct uloop_timeout *t)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment