.ad 8
.bm 8
.fm 4
.bt $Copyright (c) 1999-2005 SAP AG$$Page %$
.tm 12
.hm 6
.hs 3
.tt 1 $NME$Project Distributed Database System$vak543c$
.tt 2 $$$
.tt 3 $$                        $1999-07-20$
***********************************************************
.nf

.nf

    ========== licence begin  GPL
    Copyright (c) 1999-2005 SAP AG

    This program 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 2
    of the License, or (at your option) any later version.

    This program 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, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
    ========== licence end
.fo


.fo
.nf
.sp
Module  :       AK HASH Procedures
=========
.sp
Purpose :
.CM *-END-* purpose -------------------------------------
.sp
.cp 3
Define  :
 
.CM *-END-* define --------------------------------------
.sp;.cp 3
Use     :
 
.CM *-END-* use -----------------------------------------
.sp;.cp 3
Synonym :
 
.CM *-END-* synonym -------------------------------------
.sp;.cp 3
Author  : HolgerB
.sp
.cp 3
Created :
.sp
.cp 3
Version : 1999-07-16
.sp
.cp 3
Release :      Date : 1999-07-20
.sp
***********************************************************
.sp
.cp 10
.fo
.oc _/1
Specification:
 
.CM *-END-* specification -------------------------------
.sp 2
***********************************************************
.sp
.cp 10
.fo
.oc _/1
Description:
 
.CM *-END-* description ---------------------------------
.sp 2
***********************************************************
.sp
.cp 10
.nf
.oc _/1
Structure:
 
.CM *-END-* structure -----------------------------------
.sp 2
**********************************************************
.sp
.cp 10
.nf
.oc _/1
.CM -lll-
Code    :
/*PRETTY*/
 
 
/*-----------------------------------------------------------*/
/*           IMPORTED FUNCTION  DECLARATION                  */
/*-----------------------------------------------------------*/
 
&ifdef TRACE
extern void                                 t01int4() ;
extern void                                 t01buf() ;
extern void                                 cccprint() ;
&else
#define                                     t01int4(a,b,c) {}
#define                                     t01buf(a,b,c,d) {}
#define                                     cccprint(x) {}
&endif
 

/*-----------------------------------------------------------*/
/*           EXPORTED FUNCTION  DECLARATION                  */
/*-----------------------------------------------------------*/
 
global void  a543hash       () ;
global void  a543init_mask  () ;
 
/*-----------------------------------------------------------*/
/*           LOCAL  FUNCTION  DECLARATION                    */
/*-----------------------------------------------------------*/
 
static void  ak543_xor_hash () ;

/*---------------------------------------------------------------------------*/
 
 
/*-----------------------------------------------------------*/
/*           MACROS                                          */
/*-----------------------------------------------------------*/

 
/*-----------------------------------------------------------*/
/*           TYPEDEF                                         */
/*-----------------------------------------------------------*/

union CharMask {
    tsp00_Uint4     in[sizeof (tsp00_Uint4)];
    char      ch[sizeof (tsp00_Uint4) * sizeof (tsp00_Uint4)];
};

#define            trace_layer_ak_sem       5
 
/*-----------------------------------------------------------*/
/*           MODUL GLOBAL VARIABLES                          */
/*-----------------------------------------------------------*/
 
static union CharMask mask;
 
/*-----------------------------------------------------------*/
global void a543hash ( hashvalue, len, hashkey )
/*-----------------------------------------------------------*/
char     *hashvalue;
tsp00_Int4 len;
tsp00_Int4 *hashkey;
{
    cccprint("AK543 a543hash  " ) ;

    t01int4 (trace_layer_ak_sem, "len         ", len ) ;
    t01buf  (trace_layer_ak_sem, hashvalue, 1, len);

    a543init_mask();
    ak543_xor_hash (hashvalue, len, hashkey);
    t01int4 (trace_layer_ak_sem, "hashkey     ", *hashkey ) ;
}
 
/*-----------------------------------------------------------*/
static void ak543_xor_hash ( hashvalue, len, hashkey )
/*-----------------------------------------------------------*/
char     *hashvalue;
tsp00_Int4 len;
tsp00_Int4 *hashkey;
{
    tsp00_Uint4     i;
    tsp00_Uint4     *c;

    cccprint("AK543 ak543_xor_" ) ;

    *hashkey = len;             
    i        = *hashkey / sizeof (tsp00_Uint4);
    c        = (tsp00_Uint4 *) hashvalue;

    t01int4 (trace_layer_ak_sem, "first key   ", *hashkey ) ;
    t01int4 (trace_layer_ak_sem, "first value ", *c ) ;

    while (i--) {

        *hashkey ^= *c++;   /* XOR in the characters. */

        t01int4 (trace_layer_ak_sem, "value in ...", *c ) ;
        t01int4 (trace_layer_ak_sem, "key in   ...", *hashkey ) ;
        t01int4 (trace_layer_ak_sem, " ... loop   ", i+1 ) ;

    }

    /* If there are any remaining characters,
     * then XOR in the rest, using a mask: */
    i = len % sizeof (tsp00_Uint4);
    if (i != 0) {

        t01int4 (trace_layer_ak_sem, "XOR mask    ", mask.in[i] ) ;

        *hashkey ^= *c & mask.in[i];

        t01int4 (trace_layer_ak_sem, "key in ...  ", *hashkey ) ;
    }

}
 
 
/*-----------------------------------------------------------*/
global void a543init_mask ()
/*-----------------------------------------------------------*/
{
    /* init hashing mask */
    tsp00_Int4       i;
    tsp00_Int4       j;

    cccprint("AK543 a543init_m" ) ;

    for (i = 0; i < sizeof (tsp00_Uint4); i++)
        for (j = 0; j < sizeof (tsp00_Uint4); j++) {
            mask.ch[sizeof (tsp00_Uint4) * i + j] = (char) (j < i ? 0xff : 0);
        }

}

.CM *-END-* code ----------------------------------------
.SP 2 
***********************************************************
*-PRETTY-*  statements    :       2544
*-PRETTY-*  lines of code :       2544        PRETTY  3.09 
*-PRETTY-*  lines in file :       2629         1992-11-23 
.PA 
