⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unique.c.unused

📁 Adhoc无线网络路由协议源码
💻 UNUSED
字号:
/*** By Bob Jenkins, February 22, 1997, Public Domain** This is an example of how to use the hash table.**** Given an input (stdin) with lines in any order**   produce an output (stdout) with duplicate lines removed.** Lines may not be longer than 4096 characters.*/#ifndef STANDARD#include "standard.h"#endif#ifndef HASHTAB#include "hashtab.h"#endif#define LINELEN 4096int main(){  ub1   buf[LINELEN];  ub1 *key;  ub4  keyl;  htab *t;  t = hcreate(8);                      /* create hash table */  /* read in all the lines */  while (gets((char *)buf))            /* get line from stdin */  {    keyl = strlen((char *)buf);    if (hadd(t, buf, keyl, (void *)0)) /* if not a duplicate */    {      key = (ub1 *)malloc(keyl);       /* dumb use of malloc */      memcpy(key, buf, keyl);          /* copy buf into key */      hkey(t)=key;                     /* replace buf with key */    }  }  if (hfirst(t)) do                    /* go to first element */  {    printf("%.*s\n",hkeyl(t),hkey(t)); /* dump it to stdout */  }  while (hnext(t));                    /* go to next element */  while (hcount(t))                    /* while the table is not empty */  {    free(hkey(t));                     /* free memory for the line */    hdel(t);                           /* delete from hash table */  }  hdestroy(t);                         /* destroy hash table */  return SUCCESS;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -