Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Functions | Variables
btree.h File Reference
#include <linux/kernel.h>
#include <linux/mempool.h>
#include <linux/btree-128.h>
#include <linux/btree-type.h>

Go to the source code of this file.

Data Structures

struct  btree_head
 

Macros

#define BTREE_TYPE_SUFFIX   l
 
#define BTREE_TYPE_BITS   BITS_PER_LONG
 
#define BTREE_TYPE_GEO   &btree_geo32
 
#define BTREE_KEYTYPE   unsigned long
 
#define btree_for_each_safel(head, key, val)
 
#define BTREE_TYPE_SUFFIX   32
 
#define BTREE_TYPE_BITS   32
 
#define BTREE_TYPE_GEO   &btree_geo32
 
#define BTREE_KEYTYPE   u32
 
#define btree_for_each_safe32(head, key, val)
 
#define BTREE_TYPE_SUFFIX   64
 
#define BTREE_TYPE_BITS   64
 
#define BTREE_TYPE_GEO   &btree_geo64
 
#define BTREE_KEYTYPE   u64
 
#define btree_for_each_safe64(head, key, val)
 

Functions

voidbtree_alloc (gfp_t gfp_mask, void *pool_data)
 
void btree_free (void *element, void *pool_data)
 
void btree_init_mempool (struct btree_head *head, mempool_t *mempool)
 
int __must_check btree_init (struct btree_head *head)
 
void btree_destroy (struct btree_head *head)
 
voidbtree_lookup (struct btree_head *head, struct btree_geo *geo, unsigned long *key)
 
int __must_check btree_insert (struct btree_head *head, struct btree_geo *geo, unsigned long *key, void *val, gfp_t gfp)
 
int btree_update (struct btree_head *head, struct btree_geo *geo, unsigned long *key, void *val)
 
voidbtree_remove (struct btree_head *head, struct btree_geo *geo, unsigned long *key)
 
int btree_merge (struct btree_head *target, struct btree_head *victim, struct btree_geo *geo, gfp_t gfp)
 
voidbtree_last (struct btree_head *head, struct btree_geo *geo, unsigned long *key)
 
voidbtree_get_prev (struct btree_head *head, struct btree_geo *geo, unsigned long *key)
 
size_t btree_visitor (struct btree_head *head, struct btree_geo *geo, unsigned long opaque, void(*func)(void *elem, unsigned long opaque, unsigned long *key, size_t index, void *func2), void *func2)
 
size_t btree_grim_visitor (struct btree_head *head, struct btree_geo *geo, unsigned long opaque, void(*func)(void *elem, unsigned long opaque, unsigned long *key, size_t index, void *func2), void *func2)
 

Variables

struct btree_geo btree_geo32
 
struct btree_geo btree_geo64
 

Macro Definition Documentation

#define btree_for_each_safe32 (   head,
  key,
  val 
)
Value:
for (val = btree_last32(head, &key); \
val; \
val = btree_get_prev32(head, &key))

Definition at line 226 of file btree.h.

#define btree_for_each_safe64 (   head,
  key,
  val 
)
Value:
for (val = btree_last64(head, &key); \
val; \
val = btree_get_prev64(head, &key))

Definition at line 238 of file btree.h.

#define btree_for_each_safel (   head,
  key,
  val 
)
Value:
for (val = btree_lastl(head, &key); \
val; \
val = btree_get_prevl(head, &key))

Definition at line 215 of file btree.h.

#define BTREE_KEYTYPE   unsigned long

Definition at line 235 of file btree.h.

#define BTREE_KEYTYPE   u32

Definition at line 235 of file btree.h.

#define BTREE_KEYTYPE   u64

Definition at line 235 of file btree.h.

#define BTREE_TYPE_BITS   BITS_PER_LONG

Definition at line 233 of file btree.h.

#define BTREE_TYPE_BITS   32

Definition at line 233 of file btree.h.

#define BTREE_TYPE_BITS   64

Definition at line 233 of file btree.h.

#define BTREE_TYPE_GEO   &btree_geo32

Definition at line 234 of file btree.h.

#define BTREE_TYPE_GEO   &btree_geo32

Definition at line 234 of file btree.h.

#define BTREE_TYPE_GEO   &btree_geo64

Definition at line 234 of file btree.h.

#define BTREE_TYPE_SUFFIX   l

Definition at line 232 of file btree.h.

#define BTREE_TYPE_SUFFIX   32

Definition at line 232 of file btree.h.

#define BTREE_TYPE_SUFFIX   64

Definition at line 232 of file btree.h.

Function Documentation

void* btree_alloc ( gfp_t  gfp_mask,
void pool_data 
)

btree_alloc - allocate function for the mempool : gfp mask for the allocation : unused

Definition at line 81 of file btree.c.

void btree_destroy ( struct btree_head head)

btree_destroy - destroy mempool

: the btree head to destroy

This function destroys the internal memory pool, use only when using btree_init(), not with btree_init_mempool().

Definition at line 199 of file btree.c.

void btree_free ( void element,
void pool_data 
)

btree_free - free function for the mempool : the element to free : unused

Definition at line 87 of file btree.c.

void* btree_get_prev ( struct btree_head head,
struct btree_geo geo,
unsigned long key 
)

btree_get_prev - get previous entry

: btree head : btree geometry : pointer to key

The function returns the next item right before the value pointed to by , and updates with its key, or returns NULL when there is no entry with a key smaller than the given key.

Definition at line 310 of file btree.c.

size_t btree_grim_visitor ( struct btree_head head,
struct btree_geo geo,
unsigned long  opaque,
void(*)(void *elem, unsigned long opaque, unsigned long *key, size_t index, void *func2)  func,
void func2 
)

Definition at line 763 of file btree.c.

int __must_check btree_init ( struct btree_head head)

btree_init - initialise a btree

: the btree head to initialise

This function allocates the memory pool that the btree needs. Returns zero or a negative error code (-ENOMEM) when memory allocation fails.

Definition at line 189 of file btree.c.

void btree_init_mempool ( struct btree_head head,
mempool_t mempool 
)

btree_init_mempool - initialise a btree with given mempool

: the btree head to initialise : the mempool to use

When this function is used, there is no need to destroy the mempool.

Definition at line 182 of file btree.c.

int __must_check btree_insert ( struct btree_head head,
struct btree_geo geo,
unsigned long key,
void val,
gfp_t  gfp 
)

btree_insert - insert an entry into the btree

: the btree to add to : the btree geometry : the key to add (must not already be present) : the value to add (must not be NULL) : allocation flags for node allocations

This function returns 0 if the item could be added, or an error code if it failed (may fail due to memory pressure).

Definition at line 509 of file btree.c.

void* btree_last ( struct btree_head head,
struct btree_geo geo,
unsigned long key 
)

btree_last - get last entry in btree

: btree head : btree geometry : last key

Returns the last entry in the btree, and sets to the key of that entry; returns NULL if the tree is empty, in that case key is not changed.

Definition at line 206 of file btree.c.

void* btree_lookup ( struct btree_head head,
struct btree_geo geo,
unsigned long key 
)

btree_lookup - look up a key in the btree

: the btree to look in : the btree geometry : the key to look up

This function returns the value for the given key, or NULL.

Definition at line 240 of file btree.c.

int btree_merge ( struct btree_head target,
struct btree_head victim,
struct btree_geo geo,
gfp_t  gfp 
)

btree_merge - merge two btrees

: the tree that gets all the entries : the tree that gets merged into : the btree geometry : allocation flags

The two trees and may not contain the same keys, that is a bug and triggers a BUG(). This function returns zero if the trees were merged successfully, and may return a failure when memory allocation fails, in which case both trees might have been partially merged, i.e. some entries have been moved from to .

Definition at line 638 of file btree.c.

void* btree_remove ( struct btree_head head,
struct btree_geo geo,
unsigned long key 
)

btree_remove - remove an entry from the btree

: the btree to update : the btree geometry : the key to remove

This function returns the removed entry, or NULL if the key could not be found.

Definition at line 628 of file btree.c.

int btree_update ( struct btree_head head,
struct btree_geo geo,
unsigned long key,
void val 
)

btree_update - update an entry in the btree

: the btree to update : the btree geometry : the key to update : the value to change it to (must not be NULL)

This function returns 0 if the update was successful, or -ENOENT if the key could not be found.

Definition at line 270 of file btree.c.

size_t btree_visitor ( struct btree_head head,
struct btree_geo geo,
unsigned long  opaque,
void(*)(void *elem, unsigned long opaque, unsigned long *key, size_t index, void *func2)  func,
void func2 
)

Definition at line 745 of file btree.c.

Variable Documentation

struct btree_geo btree_geo32

Definition at line 57 of file btree.c.

struct btree_geo btree_geo64

Definition at line 65 of file btree.c.