18a1362adSmaya/* 28a1362adSmaya * Copyright © 2019 Broadcom 38a1362adSmaya * 48a1362adSmaya * Permission is hereby granted, free of charge, to any person obtaining a 58a1362adSmaya * copy of this software and associated documentation files (the "Software"), 68a1362adSmaya * to deal in the Software without restriction, including without limitation 78a1362adSmaya * the rights to use, copy, modify, merge, publish, distribute, sublicense, 88a1362adSmaya * and/or sell copies of the Software, and to permit persons to whom the 98a1362adSmaya * Software is furnished to do so, subject to the following conditions: 108a1362adSmaya * 118a1362adSmaya * The above copyright notice and this permission notice (including the next 128a1362adSmaya * paragraph) shall be included in all copies or substantial portions of the 138a1362adSmaya * Software. 148a1362adSmaya * 158a1362adSmaya * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 168a1362adSmaya * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 178a1362adSmaya * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 188a1362adSmaya * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 198a1362adSmaya * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 208a1362adSmaya * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 218a1362adSmaya * IN THE SOFTWARE. 228a1362adSmaya */ 238a1362adSmaya 248a1362adSmaya#ifndef DAG_H 258a1362adSmaya#define DAG_H 268a1362adSmaya 278a1362adSmaya#include <stdint.h> 288a1362adSmaya#include "util/list.h" 298a1362adSmaya#include "util/u_dynarray.h" 308a1362adSmaya 318a1362adSmaya#ifdef __cplusplus 328a1362adSmayaextern "C" { 338a1362adSmaya#endif 348a1362adSmaya 358a1362adSmayastruct dag_edge { 368a1362adSmaya struct dag_node *child; 378a1362adSmaya /* User-defined data associated with the edge. */ 388a1362adSmaya void *data; 398a1362adSmaya}; 408a1362adSmaya 418a1362adSmayastruct dag_node { 428a1362adSmaya /* Position in the DAG heads list (or a self-link) */ 438a1362adSmaya struct list_head link; 448a1362adSmaya /* Array struct edge to the children. */ 458a1362adSmaya struct util_dynarray edges; 468a1362adSmaya uint32_t parent_count; 478a1362adSmaya}; 488a1362adSmaya 498a1362adSmayastruct dag { 508a1362adSmaya struct list_head heads; 518a1362adSmaya}; 528a1362adSmaya 538a1362adSmayastruct dag *dag_create(void *mem_ctx); 548a1362adSmayavoid dag_init_node(struct dag *dag, struct dag_node *node); 558a1362adSmayavoid dag_add_edge(struct dag_node *parent, struct dag_node *child, void *data); 568a1362adSmayavoid dag_remove_edge(struct dag *dag, struct dag_edge *edge); 578a1362adSmayavoid dag_traverse_bottom_up(struct dag *dag, void (*cb)(struct dag_node *node, 588a1362adSmaya void *data), void *data); 598a1362adSmayavoid dag_prune_head(struct dag *dag, struct dag_node *node); 608a1362adSmaya 618a1362adSmaya#ifdef __cplusplus 628a1362adSmaya} 638a1362adSmaya#endif 648a1362adSmaya 658a1362adSmaya#endif 66