src/sppool.h File Reference

The Main library header. More...

#include "spstring.h"
Include dependency graph for sppool.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  stringpool
 An easy way to menage a pool of strings. More...

Defines

#define MAX_DIM_STRING_POOL   50
 The size of strings array into stringpool struct.
#define UNUSED_SLOT   0
 Make the code easier to read.
#define USED_SLOT   1
 Make the code easier to read.

Functions

void sp_initialize_stringpool (stringpool *sp)
 Inizialize the given stringpool struct.
void sp_free_stringpool (stringpool *sp)
 Free the memory for any string saved into stringpool.strings array.
int sp_sizeof (const stringpool *sp)
 This simple function return how many strings are into given stringpool.
bool sp_isempty (const stringpool *sp)
 This simple function return a bool value based on stringpool size.
bool sp_isfull (const stringpool *sp)
 This simple function return a bool value based on stringpool size.
int sp_find_string (const stringpool *sp, const string str)
 The function search the given string inside the stringpool.
string sp_get_string (const stringpool *sp, int pos)
 This function fetch the string which is present in position pos in the stringpool.
void sp_add_string (stringpool *sp, const string str)
 This function adds the string str into the stringpool pointed by sp.
void sp_add_string_pos (stringpool *sp, const string str, int pos)
 This is a function adds the string str in position pos into the stringpool.
string sp_remove_string (stringpool *sp, int pos)
 This function remove the string in position pos into the stringpool.
void sp_replace_string (stringpool *sp, int pos, string str)
 This function replace the an old string , in position pos, with str into the stringpool pointed by sp.
int sp_save_to_file (stringpool *sp, const string fname)
 This function save the stringpool content in the given text file.
int sp_load_from_file (stringpool *sp, const string fname)
 This function load the file content into the stringpool.
void bubble_sort (stringpool *sp)
 A simple sorting function.
int bin_search (const stringpool *sp, const string str)
 This function search the string inside the sorted stringpool using the binary search algorithm.

Detailed Description

The Main library header.

Author:
Andrea Florio <andrea@opensuse.org>
Giuseppe Grassi <gra.giu@alice.it>
Version:
0.2
Date:
2010

License

Copyright (C) 2010
Andrea Florio 2010 <andrea@opensuse.org>
Giuseppe Grassi 2010 <gra.giu@alice.it>

This Project is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This Project is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.


Define Documentation

#define MAX_DIM_STRING_POOL   50

The size of strings array into stringpool struct.

#define UNUSED_SLOT   0

Make the code easier to read.

#define USED_SLOT   1

Make the code easier to read.


Function Documentation

int bin_search ( const stringpool sp,
const string  str 
)

This function search the string inside the sorted stringpool using the binary search algorithm.

Warning:
The stringpool pointed my sp MUST already been sorted previously, argument *sp is const, the string will not been changed by that function.
Parameters:
*sp Is the pointer to the stringpool.
str Is the string to search into sp.
Returns:
the position of the string if str is found, else -1 is returned.
void bubble_sort ( stringpool sp  ) 

A simple sorting function.

stringpool elements are sorted alphabetically using bubble sort algorithm.

Parameters:
*sp Is the pointer to the stringpool to sort.
void sp_add_string ( stringpool sp,
const string  str 
)

This function adds the string str into the stringpool pointed by sp.

Parameters:
*sp Is the pointer to the stringpool.
str Is the string to add into sp.
void sp_add_string_pos ( stringpool sp,
const string  str,
int  pos 
)

This is a function adds the string str in position pos into the stringpool.

Parameters:
*sp Is the pointer to the stringpool.
pos Is the position where str will be added.
str Is the string to add into sp.
int sp_find_string ( const stringpool sp,
const string  str 
)

The function search the given string inside the stringpool.

Parameters:
*sp Is the pointer to the stringpool.
str Is the string to search into the stringpool.
Returns:
the position of the string into the stringpool; or -1 if not present or *sp and str are invalid (NULL).
void sp_free_stringpool ( stringpool sp  ) 

Free the memory for any string saved into stringpool.strings array.

stringpool.used_counter and stringpool.positions are initialized to 0.

Parameters:
*sp Is the pointer to the stringpool to free.
string sp_get_string ( const stringpool sp,
int  pos 
)

This function fetch the string which is present in position pos in the stringpool.

Parameters:
*sp Is the pointer to the stringpool.
pos Is position of the desired string.
Returns:
The string in position pos into the stringpool or NULL if 0 > pos > MAX_DIM_STRING_POOL or sp is NULL.
void sp_initialize_stringpool ( stringpool sp  ) 

Inizialize the given stringpool struct.

Parameters:
sp Is a pointer to a stringpool struct.
bool sp_isempty ( const stringpool sp  ) 

This simple function return a bool value based on stringpool size.

Parameters:
*sp Is the pointer to the stringpool.
Returns:
TRUE if given stringpool is empty, else return FALSE.
bool sp_isfull ( const stringpool sp  ) 

This simple function return a bool value based on stringpool size.

Parameters:
*sp Is the pointer to the stringpool.
Returns:
TRUE if given stringpool is full, else return FALSE.
int sp_load_from_file ( stringpool sp,
const string  fname 
)

This function load the file content into the stringpool.

Parameters:
*sp Is the pointer to the stringpool.
fname Is the file from where the data will be red.
Returns:
the number of elements red from file, or -1 in case of errors.
string sp_remove_string ( stringpool sp,
int  pos 
)

This function remove the string in position pos into the stringpool.

Parameters:
*sp Is the pointer to the stringpool.
pos is the position where str will be removed.
Returns:
a copy of the string removed from stringpool, or NULL if no string exist in position pos or if 0 > pos > MAX_DIM_STRING_POOL or sp is NULL.
void sp_replace_string ( stringpool sp,
int  pos,
string  str 
)

This function replace the an old string , in position pos, with str into the stringpool pointed by sp.

Parameters:
*sp Is the pointer to the stringpool.
pos Is the position where the new string will replace the old one.
str Is the new string that will replace the old one.
int sp_save_to_file ( stringpool sp,
const string  fname 
)

This function save the stringpool content in the given text file.

Parameters:
*sp Is the pointer to the stringpool.
fname Is the file to use for writing.
Returns:
the number of the written elements or -1 in case of errors.
int sp_sizeof ( const stringpool sp  ) 

This simple function return how many strings are into given stringpool.

Parameters:
*sp Is the pointer to the stringpool.
Returns:
the number of strings existing into the stringpool. or -1 if *sp is NULL.
 All Data Structures Files Functions Variables Typedefs Defines
Generated on Thu Jun 10 16:35:58 2010 for libstringpool by  doxygen 1.6.3