现在的位置: 首页 > 综合 > 正文

GoAhead2.5源代码分析之8-sym hash table(sym.c)

2012年02月07日 ⁄ 综合 ⁄ 共 3121字 ⁄ 字号 评论关闭

sym.csymbol hash table

typedef struct {                                         /* Symbol table descriptor */

       int           inuse;                                         /* Is this entry in use */

       int           hash_size;                                   /* Size of the table below */

       sym_t     **hash_table;                       /* Allocated at run time */

} sym_tabent_t;

 

 

typedef struct sym_t {

       struct sym_t   *forw;                                /* Pointer to next hash list */

       value_t                  name;                                  /* Name of symbol */

       value_t                  content;                        /* Value of symbol */

       int                         arg;                              /* Parameter value */

} sym_t;

 

sym_tabent_t结构表示一个hash表,hash_table[n]指向hash表中的分支n,每个分支n有结构体sym_t表示,每个分支中,有多个sym_t组成,它们组成了一个单向链表,每个sym_t代表一个名、值对。

-----------------------------------------------------------------------------------------------------------------

int symSubOpen()

功能:打开symbol table,初始化。

说明:

-----------------------------------------------------------------------------------------------------------------

 

void symSubClose()

功能:关闭sysbol table

说明:

-----------------------------------------------------------------------------------------------------------------

 

sym_fd_t symOpen(int hash_size)

功能:创建一个 sysbol table

说明:

-----------------------------------------------------------------------------------------------------------------

 

void symClose(sym_fd_t sd)

功能:关闭sysbol table,释放分配的内存。

说明:

-----------------------------------------------------------------------------------------------------------------

 

sym_t* symFirst(sym_fd_t sd)

功能:找到指定sdhash table中第一个symbol

说明:

-----------------------------------------------------------------------------------------------------------------

 

sym_t* symNext(sym_fd_t sd)

功能:找到下一个symbol

说明:

-----------------------------------------------------------------------------------------------------------------

 

sym_t *symLookup(sym_fd_t sd, char_t *name)

功能:在sd hash table中找到名字为namehash

说明:

-----------------------------------------------------------------------------------------------------------------

 

sym_t *symEnter(sym_fd_t sd, char_t *name, value_t v, int arg)

功能:进入hash表中,更新值

说明:

-----------------------------------------------------------------------------------------------------------------

 

int symDelete(sym_fd_t sd, char_t *name)

功能:删除hash表中对应的值。

说明:

-----------------------------------------------------------------------------------------------------------------

 

static sym_t *hash(sym_tabent_t *tp, char_t *name)

功能:根据name找到hash表中对应的值

说明:

-----------------------------------------------------------------------------------------------------------------

 

static int hashIndex(sym_tabent_t *tp, char_t *name)

功能:计算hash索引。一种计算方法而已!

说明:

-----------------------------------------------------------------------------------------------------------------

 

static int isPrime(int n)

功能:核实n是否是素数

说明:

-----------------------------------------------------------------------------------------------------------------

 

static int calcPrime(int size)

功能:找到小于size的最大的素数

说明:

-----------------------------------------------------------------------------------------------------------------

抱歉!评论已关闭.