From patchwork Thu Jun 16 20:29:55 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 2012 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id CC2F823F3F for ; Thu, 16 Jun 2011 20:31:58 +0000 (UTC) Received: from mail-vw0-f50.google.com (mail-vw0-f50.google.com [209.85.212.50]) by fiordland.canonical.com (Postfix) with ESMTP id 97147A18905 for ; Thu, 16 Jun 2011 20:31:58 +0000 (UTC) Received: by mail-vw0-f50.google.com with SMTP id 14so1756184vws.37 for ; Thu, 16 Jun 2011 13:31:58 -0700 (PDT) Received: by 10.52.98.97 with SMTP id eh1mr1965280vdb.7.1308256317457; Thu, 16 Jun 2011 13:31:57 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.52.183.130 with SMTP id em2cs211233vdc; Thu, 16 Jun 2011 13:31:57 -0700 (PDT) Received: by 10.217.7.7 with SMTP id z7mr915380wes.14.1308256310808; Thu, 16 Jun 2011 13:31:50 -0700 (PDT) Received: from smtp.smtpout.orange.fr (smtp08.smtpout.orange.fr [80.12.242.130]) by mx.google.com with ESMTP id g84si5068137wes.80.2011.06.16.13.31.50; Thu, 16 Jun 2011 13:31:50 -0700 (PDT) Received-SPF: neutral (google.com: 80.12.242.130 is neither permitted nor denied by best guess record for domain of daniel.lezcano@linaro.org) client-ip=80.12.242.130; Authentication-Results: mx.google.com; spf=neutral (google.com: 80.12.242.130 is neither permitted nor denied by best guess record for domain of daniel.lezcano@linaro.org) smtp.mail=daniel.lezcano@linaro.org Received: from monster.dhcp.lxc ([92.134.76.78]) by mwinf5d16 with ME id wkXf1g0031hMfSL03kXpKb; Thu, 16 Jun 2011 22:31:50 +0200 From: Daniel Lezcano To: patches@linaro.org Subject: [PATCH 26/28] document the tree code Date: Thu, 16 Jun 2011 22:29:55 +0200 Message-Id: <1308256197-29155-26-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1308256197-29155-1-git-send-email-daniel.lezcano@linaro.org> References: <1308256197-29155-1-git-send-email-daniel.lezcano@linaro.org> Signed-off-by: Daniel Lezcano --- tree.c | 35 +++++++++++++++++++++++++++++++++++ 1 files changed, 35 insertions(+), 0 deletions(-) diff --git a/tree.c b/tree.c index dd53ff2..f95610a 100644 --- a/tree.c +++ b/tree.c @@ -227,6 +227,15 @@ int tree_for_each(struct tree *tree, tree_cb_t cb, void *data) return tree_for_each(tree->next, cb, data); } +/* + * This function will go over the tree passed as parameter at the reverse + * order and will call the callback passed as parameter for each. + * @tree : the lower node where we begin to browse the tree at the reverse + * order + * cb : a callback for each node the function will go over + * data : some private data to be passed across the callbacks + * Returns 0 on success, < 0 otherwise + */ int tree_for_each_reverse(struct tree *tree, tree_cb_t cb, void *data) { if (!tree) @@ -241,6 +250,15 @@ int tree_for_each_reverse(struct tree *tree, tree_cb_t cb, void *data) return tree_for_each_reverse(tree->parent, cb, data); } + +/* + * The function will go over all the parent of the specified node passed + * as parameter. + * @tree : the child node from where we back path to the parent + * cb : a callback for each node the function will go over + * data : some private data to be passed across the callbacks + * Returns 0 on success, < 0 otherwise + */ int tree_for_each_parent(struct tree *tree, tree_cb_t cb, void *data) { if (!tree) @@ -252,6 +270,13 @@ int tree_for_each_parent(struct tree *tree, tree_cb_t cb, void *data) return cb(tree, data); } +/* + * The function will return the first node which match with the name as + * parameter. + * @tree : the tree where we begin to find + * @name : the name of the node the function must look for. + * Returns a pointer to the tree structure if found, NULL otherwise. + */ struct tree *tree_find(struct tree *tree, const char *name) { struct tree *t; @@ -290,6 +315,16 @@ static int tree_finds_cb(struct tree *tree, void *data) return 0; } +/* + * This function will search for all the nodes where the name begin + * with the name passed as parameter. *Note* the function allocates + * the array, it is up to the caller to free this array. + * @tree : the topmost node of the tree where we being to search + * @name : the name to find in the tree + * @ptr : a pointer to a pointer of pointer of tree structure :) + * Returns the number of elements found in the tree, < 0 if something + * went wrong. + */ int tree_finds(struct tree *tree, const char *name, struct tree ***ptr) { struct struct_find sf = { .nr = 0, .ptree = NULL, .name = name };