hashDefault.c

Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <string.h>
00003 
00004 /**
00005  * This is the default hash, used by labeled stream if user does not provide one. Hash is used by the labeled stream
00006  * after the getLabel extracts the label from the message. After hashing the label, we have the destination of the
00007  * message.
00008  * \param label the label of the message, extracted by getLabel
00009  * \param image the number of destinations valid
00010  * \return the destination instance, something >=0 and < image
00011  */ 
00012 int hashDefault(char *label, int numDestinations){
00013         int i, labelSize, key = 0;
00014         labelSize = strlen((char *)label);
00015         
00016         for(i = 0; i < labelSize; i++){
00017                 key +=  (int)label[i];
00018         }
00019         return(key % numDestinations);
00020 }
00021 
00022 
00023 /**
00024  * Similar to default hash, but the result is a set of destinations, not a single one. The array size is given by the
00025  * the image parameter.
00026  * \param label the label of the message, extracted by getLabel
00027  * \param image the number of destinations valid
00028  * \param destArray a "boolean" array, where each positions says if a destination is valid or not. \
00029         The array size is given by the image parameter. Void allocates it.
00030  */
00031 void mlsHashDefault(char *label, int numDestinations, int destArray[]){
00032         int i;
00033 
00034         for (i=0;i<numDestinations;i++){
00035                 
00036                 int j, labelSize, key = 0;
00037                 labelSize = strlen((char *)label);
00038 
00039                 for(j = 0; j < labelSize; j++){
00040                         key +=  (int)label[j];
00041                 }
00042                 key = key % 2; //true or false
00043 
00044                 destArray[i] = key;
00045         }
00046 
00047 }

Generated on Tue Jan 17 19:18:38 2006 for Void by  doxygen 1.4.6