CDC/ECM driver for mbed, based on USBDevice by mbed-official. Uses PicoTCP to access Ethernet USB device. License: GPLv2
Fork of USB_Ethernet by
include/pico_tree.h@2:540f6e142d59, 2013-08-03 (annotated)
- Committer:
- daniele
- Date:
- Sat Aug 03 13:16:14 2013 +0000
- Revision:
- 2:540f6e142d59
Moved to single package
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
daniele | 2:540f6e142d59 | 1 | /********************************************************************* |
daniele | 2:540f6e142d59 | 2 | PicoTCP. Copyright (c) 2012 TASS Belgium NV. Some rights reserved. |
daniele | 2:540f6e142d59 | 3 | See LICENSE and COPYING for usage. |
daniele | 2:540f6e142d59 | 4 | |
daniele | 2:540f6e142d59 | 5 | Author: Andrei Carp <andrei.carp@tass.be> |
daniele | 2:540f6e142d59 | 6 | *********************************************************************/ |
daniele | 2:540f6e142d59 | 7 | |
daniele | 2:540f6e142d59 | 8 | #ifndef __PICO_RBTREE_H__ |
daniele | 2:540f6e142d59 | 9 | #define __PICO_RBTREE_H__ |
daniele | 2:540f6e142d59 | 10 | |
daniele | 2:540f6e142d59 | 11 | #include <stdint.h> |
daniele | 2:540f6e142d59 | 12 | #include "pico_config.h" |
daniele | 2:540f6e142d59 | 13 | |
daniele | 2:540f6e142d59 | 14 | // This is used to declare a new tree, leaf root by default |
daniele | 2:540f6e142d59 | 15 | #define PICO_TREE_DECLARE(name,compareFunction) \ |
daniele | 2:540f6e142d59 | 16 | struct pico_tree name =\ |
daniele | 2:540f6e142d59 | 17 | { \ |
daniele | 2:540f6e142d59 | 18 | &LEAF, \ |
daniele | 2:540f6e142d59 | 19 | compareFunction \ |
daniele | 2:540f6e142d59 | 20 | } |
daniele | 2:540f6e142d59 | 21 | |
daniele | 2:540f6e142d59 | 22 | struct pico_tree_node |
daniele | 2:540f6e142d59 | 23 | { |
daniele | 2:540f6e142d59 | 24 | void* keyValue; // generic key |
daniele | 2:540f6e142d59 | 25 | struct pico_tree_node* parent; |
daniele | 2:540f6e142d59 | 26 | struct pico_tree_node* leftChild; |
daniele | 2:540f6e142d59 | 27 | struct pico_tree_node* rightChild; |
daniele | 2:540f6e142d59 | 28 | uint8_t color; |
daniele | 2:540f6e142d59 | 29 | }; |
daniele | 2:540f6e142d59 | 30 | |
daniele | 2:540f6e142d59 | 31 | struct pico_tree |
daniele | 2:540f6e142d59 | 32 | { |
daniele | 2:540f6e142d59 | 33 | struct pico_tree_node * root; // root of the tree |
daniele | 2:540f6e142d59 | 34 | |
daniele | 2:540f6e142d59 | 35 | // this function directly provides the keys as parameters not the nodes. |
daniele | 2:540f6e142d59 | 36 | int (*compare)(void* keyA, void* keyB); |
daniele | 2:540f6e142d59 | 37 | }; |
daniele | 2:540f6e142d59 | 38 | |
daniele | 2:540f6e142d59 | 39 | extern struct pico_tree_node LEAF; // generic leaf node |
daniele | 2:540f6e142d59 | 40 | /* |
daniele | 2:540f6e142d59 | 41 | * Manipulation functions |
daniele | 2:540f6e142d59 | 42 | */ |
daniele | 2:540f6e142d59 | 43 | void * pico_tree_insert(struct pico_tree * tree, void * key); |
daniele | 2:540f6e142d59 | 44 | void * pico_tree_delete(struct pico_tree * tree, void * key); |
daniele | 2:540f6e142d59 | 45 | void * pico_tree_findKey(struct pico_tree * tree, void * key); |
daniele | 2:540f6e142d59 | 46 | void pico_tree_drop(struct pico_tree * tree); |
daniele | 2:540f6e142d59 | 47 | int pico_tree_empty(struct pico_tree * tree); |
daniele | 2:540f6e142d59 | 48 | struct pico_tree_node * pico_tree_findNode(struct pico_tree * tree, void * key); |
daniele | 2:540f6e142d59 | 49 | |
daniele | 2:540f6e142d59 | 50 | void * pico_tree_first(struct pico_tree * tree); |
daniele | 2:540f6e142d59 | 51 | void * pico_tree_last(struct pico_tree * tree); |
daniele | 2:540f6e142d59 | 52 | /* |
daniele | 2:540f6e142d59 | 53 | * Traverse functions |
daniele | 2:540f6e142d59 | 54 | */ |
daniele | 2:540f6e142d59 | 55 | struct pico_tree_node * pico_tree_lastNode(struct pico_tree_node * node); |
daniele | 2:540f6e142d59 | 56 | struct pico_tree_node * pico_tree_firstNode(struct pico_tree_node * node); |
daniele | 2:540f6e142d59 | 57 | struct pico_tree_node * pico_tree_next(struct pico_tree_node * node); |
daniele | 2:540f6e142d59 | 58 | struct pico_tree_node * pico_tree_prev(struct pico_tree_node * node); |
daniele | 2:540f6e142d59 | 59 | |
daniele | 2:540f6e142d59 | 60 | /* |
daniele | 2:540f6e142d59 | 61 | * For each macros |
daniele | 2:540f6e142d59 | 62 | */ |
daniele | 2:540f6e142d59 | 63 | |
daniele | 2:540f6e142d59 | 64 | #define pico_tree_foreach(idx,tree) \ |
daniele | 2:540f6e142d59 | 65 | for ((idx) = pico_tree_firstNode((tree)->root); \ |
daniele | 2:540f6e142d59 | 66 | (idx) != &LEAF; \ |
daniele | 2:540f6e142d59 | 67 | (idx) = pico_tree_next(idx)) |
daniele | 2:540f6e142d59 | 68 | |
daniele | 2:540f6e142d59 | 69 | #define pico_tree_foreach_reverse(idx,tree) \ |
daniele | 2:540f6e142d59 | 70 | for ((idx) = pico_tree_lastNode((tree)->root); \ |
daniele | 2:540f6e142d59 | 71 | (idx) != &LEAF; \ |
daniele | 2:540f6e142d59 | 72 | (idx) = pico_tree_prev(idx)) |
daniele | 2:540f6e142d59 | 73 | |
daniele | 2:540f6e142d59 | 74 | #define pico_tree_foreach_safe(idx,tree,idx2) \ |
daniele | 2:540f6e142d59 | 75 | for ((idx) = pico_tree_firstNode((tree)->root); \ |
daniele | 2:540f6e142d59 | 76 | ((idx) != &LEAF) && ((idx2) = pico_tree_next(idx), 1); \ |
daniele | 2:540f6e142d59 | 77 | (idx) = (idx2)) |
daniele | 2:540f6e142d59 | 78 | |
daniele | 2:540f6e142d59 | 79 | #define pico_tree_foreach_reverse_safe(idx,tree,idx2) \ |
daniele | 2:540f6e142d59 | 80 | for ((idx) = pico_tree_lastNode((tree)->root); \ |
daniele | 2:540f6e142d59 | 81 | ((idx) != &LEAF) && ((idx2) = pico_tree_prev(idx), 1); \ |
daniele | 2:540f6e142d59 | 82 | (idx) = (idx2)) |
daniele | 2:540f6e142d59 | 83 | |
daniele | 2:540f6e142d59 | 84 | #endif |