@@ -494,9 +494,6 @@ iam_list_s a_star_iam_list(const iam_graph_s * graph, const iam_cost_s * cost, c
494494 return (iam_list_s ) { 0 };
495495}
496496
497- void map_cost_iam_list (const iam_graph_s * graph , const iam_list_s * table , const size_t start , const handle_fn handle , void * arguments ) {
498- }
499-
500497void destroy_iam_list (const iam_graph_s * graph , iam_list_s * table ) {
501498 free (table -> cost );
502499 free (table -> previous );
@@ -508,17 +505,51 @@ iam_graph_s subgraph_iam_list(const iam_graph_s * graph, const iam_list_s * tabl
508505 return (iam_graph_s ) { 0 };
509506}
510507
511- void map_vertex_iam_graph (const iam_graph_s * graph , const handle_fn handle , void * arguments ) {
508+ void each_vertex_iam_graph (const iam_graph_s * graph , const handle_fn handle , void * arguments ) {
512509 for (char * v = graph -> vertices ; v < graph -> vertices + (graph -> length * graph -> vertex_size ); v += graph -> vertex_size ) {
513510 if (!handle (v , arguments )) { return ; } // if handler terminates (returns false) end loop
514511 }
515512}
516513
517- void map_edge_iam_graph (const iam_graph_s * graph , const handle_fn handle , void * arguments ) {
514+ void each_edge_iam_graph (const iam_graph_s * graph , const handle_fn handle , void * arguments ) {
518515 const size_t edge_length = (graph -> length * (graph -> length - 1 )) / 2 ;
519516 for (char * e = graph -> edges ; e < graph -> edges + (edge_length * graph -> edge_size ); e += graph -> edge_size ) {
520- if (!graph -> compare (e , graph -> none )) { continue ; } // if edge is none continue since handle can't be performed
521- if (!handle (e , arguments )) { return ; } // if handler terminates (returns false) end loop
517+ // if edge is none continue since handle can't be performed (first condition is false so other won't be checked.)
518+ // if handler terminates (returns false) end loop
519+ if (graph -> compare (e , graph -> none ) && !handle (e , arguments )) {
520+ break ;
521+ }
522+ }
523+ }
524+
525+ void each_neighbor_iam_graph (iam_graph_s const * const graph , size_t const index , handle_fn const handle , void * const arguments ) {
526+ const size_t offset = (index * (index - 1 )) / 2 ;
527+ for (size_t i = 0 , e = offset ; i < index ; ++ i , e ++ ) {
528+ char const * edge = graph -> edges + (e * graph -> edge_size );
529+ char * vertex = graph -> vertices + (i * graph -> vertex_size );
530+
531+ // if edge is none continue since handle can't be performed (first condition is false so other won't be checked.)
532+ // if handler terminates (returns false) end loop
533+ if (graph -> compare (edge , graph -> none ) && !handle (vertex , arguments )) {
534+ return ;
535+ }
536+ }
537+
538+ for (size_t i = index + 1 , e = offset + (2 * index ); i < graph -> length ; e += i ++ ) {
539+ char const * edge = graph -> edges + (e * graph -> edge_size );
540+ char * vertex = graph -> vertices + (i * graph -> vertex_size );
541+
542+ // if edge is none continue since handle can't be performed (first condition is false so other won't be checked.)
543+ // if handler terminates (returns false) end loop
544+ if (graph -> compare (edge , graph -> none ) && !handle (vertex , arguments )) {
545+ return ;
546+ }
547+ }
548+ }
549+
550+ void each_cost_iam_list (const iam_graph_s * graph , const iam_list_s * table , const size_t start , const handle_fn handle , void * arguments ) {
551+ for (size_t i = 0 ; i < graph -> length ; ++ i ) {
552+ if (!handle (table -> cost + (table -> data -> size * i ), arguments )) { break ; }
522553 }
523554}
524555
0 commit comments