| 1 | /***************************************************************************** |
| 2 | |
| 3 | Copyright (c) 2006, 2013, Oracle and/or its affiliates. All Rights Reserved. |
| 4 | |
| 5 | This program is free software; you can redistribute it and/or modify it under |
| 6 | the terms of the GNU General Public License as published by the Free Software |
| 7 | Foundation; version 2 of the License. |
| 8 | |
| 9 | This program is distributed in the hope that it will be useful, but WITHOUT |
| 10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 11 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 12 | |
| 13 | You should have received a copy of the GNU General Public License along with |
| 14 | this program; if not, write to the Free Software Foundation, Inc., |
| 15 | 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA |
| 16 | |
| 17 | *****************************************************************************/ |
| 18 | |
| 19 | /*******************************************************************//** |
| 20 | @file include/ut0list.ic |
| 21 | A double-linked list |
| 22 | |
| 23 | Created 4/26/2006 Osku Salerma |
| 24 | ************************************************************************/ |
| 25 | |
| 26 | /****************************************************************//** |
| 27 | Get the first node in the list. |
| 28 | @return first node, or NULL */ |
| 29 | UNIV_INLINE |
| 30 | ib_list_node_t* |
| 31 | ib_list_get_first( |
| 32 | /*==============*/ |
| 33 | ib_list_t* list) /*!< in: list */ |
| 34 | { |
| 35 | return(list->first); |
| 36 | } |
| 37 | |
| 38 | /****************************************************************//** |
| 39 | Get the last node in the list. |
| 40 | @return last node, or NULL */ |
| 41 | UNIV_INLINE |
| 42 | ib_list_node_t* |
| 43 | ib_list_get_last( |
| 44 | /*=============*/ |
| 45 | ib_list_t* list) /*!< in: list */ |
| 46 | { |
| 47 | return(list->last); |
| 48 | } |
| 49 | |
| 50 | /******************************************************************** |
| 51 | Check if list is empty. */ |
| 52 | UNIV_INLINE |
| 53 | ibool |
| 54 | ib_list_is_empty( |
| 55 | /*=============*/ |
| 56 | /* out: TRUE if empty else FALSE */ |
| 57 | const ib_list_t* list) /* in: list */ |
| 58 | { |
| 59 | return(!(list->first || list->last)); |
| 60 | } |
| 61 | |
| 62 | /******************************************************************** |
| 63 | Get number of items on list. |
| 64 | @return number of items on list */ |
| 65 | UNIV_INLINE |
| 66 | ulint |
| 67 | ib_list_len( |
| 68 | /*========*/ |
| 69 | const ib_list_t* list) /*<! in: list */ |
| 70 | { |
| 71 | ulint len = 0; |
| 72 | ib_list_node_t* node = list->first; |
| 73 | |
| 74 | while(node) { |
| 75 | len++; |
| 76 | node = node->next; |
| 77 | } |
| 78 | |
| 79 | return (len); |
| 80 | } |
| 81 | |