home *** CD-ROM | disk | FTP | other *** search
-
- /*******************************************************************
- $CRT 26 Oct 1996 : hb
-
- $AUT Holger Burkarth
- $DAT >>TstHash.c<< 29 Jan 1997 13:19:16 - (C) ProDAD
- *******************************************************************/
-
- //##ex mcpp:cppc -gs -o pos:pos/Ex/TstHash p:pLib/StartCode.o p:/pOS_RKRM/pUtility/TstHash.c p:pLib/StdIO.o -l pOSStub -l pOS
-
- /***********************************************************
- pOS programing example - Copyright (C) 1995-97 proDAD
-
- This code was written as an easy to understand example,
- how to program pOS features. It is provided 'as-is',
- without any express or implied warranty.
-
- Permission is hereby granted to use, copy and modify
- this source code for any purpose, without fee, subject
- to the following conditions:
-
- (1) This notice may not be removed or altered from any
- source distribution.
-
- (2) Altered source versions must be plainly marked as
- such, and must not be misrepresented as being
- the original source code.
-
- (3) If only executable code is distributed, then the
- accompanying documentation have to state that
- "this software is based in part on examples of
- the pOS developer packet".
-
- (4) Permission for use of this code is granted only
- if the user accepts full responsibility for any
- undesirable consequences. proDAD accept NO LIABILITY
- for damages of any kind.
-
- ©proDAD
- ***********************************************************/
-
- /*\
- *** Example:
- ***
- \*/
-
-
- #define __COMPUTER_AMIGA 1
- #define NOMYDEBUG
-
- #include "p:pExec/Types.h"
- #include "p:pDOS/ArgTags.h"
- #include "p:pDOS/DosSig.h"
- #include "p:pDOS/DosErrors.h"
- #include "p:pUtil/Hash.h"
- #include "p:proto/pLibExt.h"
- #include "p:proto/pExec2.h"
- #include "p:proto/pDOS2.h"
- #include "p:proto/pUtil2.h"
-
-
- #ifdef _____ME_____
- #include "grund/inc_string.h"
- #include "grund/inc_stdio.h"
- #else
- #ifdef __cplusplus
- extern "C" {
- #endif
- #include <string.h>
- #include <stdio.h>
- #ifdef __cplusplus
- }
- #endif
- #endif
-
-
- const CHAR *HelpText=
- ""
- ;
-
- const CHAR *PrgHeader=
- "";
-
- const CHAR *PrgVerText=
- "$VER: 1.0 ("__DATE2__") (Copyright 1996-97 by proDAD) (Created by Holger Burkarth)";
-
- struct pOS_UtilityBase *gb_UtilityBase;
-
- static const CHAR *Names[]=
- {
- "null",
- "eins",
- "zwei",
- "drei",
- "vier",
- "fünf",
- "sechs",
- "sieben",
- "acht",
- "neun",
- "zen",
- "Text",
- "pOS",
- "proDAD",
- "Hash",
- NULL
- };
-
- static UWORD gb_Hash;
-
-
-
- /*----------------------------------
- -----------------------------------*/
- VOID FillHash(struct pOS_HashList* hl,BOOL prt)
- {
- ULONG i;
-
- for(i=0; Names[i]!=NULL; ++i) {
- pOS_HashNode *HN;
-
- HN=pOS_CreateHashNode(hl,(VOID*)Names[i]);
- if(HN) {
- pOS_AddHashNode(hl,HN);
- if(prt) printf("AddNode 0x%lx |%s|\n",HN,Names[i]);
- }
- else {
- printf("Cannot create HashNode\n");
- break;
- }
- }
- }
-
-
- /*----------------------------------
- -----------------------------------*/
- VOID PrintHash(const struct pOS_HashList* hl)
- {
- ULONG i,Sum;
- const struct pOS_HashNode *HN;
-
- printf("Hash-Verteilung bei %ld\n\n",gb_Hash);
-
- for(i=0; i<hl->hl_LstNum; ++i) {
- const struct pOS_List *const Lst=&hl->hl_List[i];
-
- Sum=0;
- for(HN=(struct pOS_HashNode*)Lst->lh_Head;
- HN->hn_Node.ln_Succ;
- HN=(struct pOS_HashNode*)HN->hn_Node.ln_Succ)
- {
- ++Sum;
- }
- printf("Index %3ld Sum=%ld\n",i,Sum);
- }
- }
-
-
- /*----------------------------------
- -----------------------------------*/
- static
- ULONG StrHash_func(_R_A0 const struct pOS_HashList* hl,_R_A1 const VOID* data)
- {
- ULONG Sum;
- const UBYTE *Str=(UBYTE*)data;
-
- for(Sum=0; *Str; ++Str) {
- Sum=Sum*gb_Hash + (Str[0] - '0');
- }
-
- return(Sum % hl->hl_LstNum);
- }
-
-
-
-
- /*----------------------------------
- -----------------------------------*/
- #ifdef __cplusplus
- extern "C"
- #endif
-
- VOID main()
- {
- struct pOS_DosArgs* Args;
- ULONG Ops[2]={7,1};
-
- gb_UtilityBase=(struct pOS_UtilityBase*)pOS_OpenLibrary("pUtility.library",0);
-
-
- Args=pOS_ReadDosArgs(
- // 0 1
- "HASH/N, VERBOSE/S",
- Ops,sizeof(Ops)/sizeof(ULONG),
-
- ARGTAG_PrgHeaderText, (ULONG)PrgHeader, /* kurze Programm-Beschreibung */
- ARGTAG_HelpText, (ULONG)HelpText, /* Help-Texte */
- ARGTAG_PrgVerText, (ULONG)PrgVerText, /* VER-String */
- TAG_END);
-
- if(Args) {
- struct pOS_HashList *HL;
- struct pOS_HashNode *HN;
- ULONG i;
-
- gb_Hash=*((ULONG*)Ops[0]);
-
- HL=pOS_CreateHash(13);
- if(HL) {
- HL->hl_Hash_func=StrHash_func; // *** überschreibe System-Default
-
- FillHash(HL,Ops[1]);
- if(Ops[1]) {
- for(i=0; Names[i]!=NULL; ++i) {
- HN=pOS_MatchHash(HL,(APTR)Names[i]);
- if(HN) printf("Found |%s| 0x%lx\n",Names[i],HN);
- else printf("FATAL |%s|\n",Names[i]);
- }
- }
- PrintHash(HL);
-
- pOS_DeleteHash(HL);
- }
- pOS_DeleteDosArgs(Args);
- }
-
- pOS_CloseLibrary((pOS_Library*)gb_UtilityBase);
- }
-