*** empty log message ***

This commit is contained in:
hyung-hwan 2005-05-10 06:02:19 +00:00
parent 1465153007
commit 4b35c301d1
3 changed files with 72 additions and 37 deletions

View File

@ -1,10 +1,11 @@
/*
* $Id: hash.c,v 1.2 2005-05-09 15:55:04 bacon Exp $
* $Id: hash.c,v 1.3 2005-05-10 06:02:19 bacon Exp $
*/
#include <xp/stx/hash.h>
int xp_stx_new_link (xp_stx_t* stx, xp_stx_word_t key, xp_stx_word_t value)
xp_stx_word_t xp_stx_new_link (
xp_stx_t* stx, xp_stx_word_t key, xp_stx_word_t value)
{
xp_stx_word_t x;
@ -17,42 +18,58 @@ int xp_stx_new_link (xp_stx_t* stx, xp_stx_word_t key, xp_stx_word_t value)
return x;
}
void xp_stx_hash_insert (
xp_stx_t* stx, xp_stx_word_t hash,
xp_stx_word_t key, xp_stx_word_t value)
/* returns the entire link */
xp_stx_word_t xp_stx_hash_lookup (
xp_stx_t* stx, xp_stx_word_t table,
xp_stx_word_t hash, xp_stx_word_t key)
{
xp_stx_word_t oaha, link;
xp_stx_word_t harr, link, next;
/* the first instance variable is an open addressing hash array */
oaha = XP_STX_AT(stx,stx->globals,0);
xp_assert (XP_STX_TYPE(stx,table) == XP_STX_INDEXED);
hash = hash % oaha_size;
link = XP_STX_AT(stx,oaha,hash);
harr = XP_STX_AT(stx,table,0);
hash = link % XP_STX_SIZE(stx,table);
link = XP_STX_AT(stx,harr,hash);
if (link == stx->nil || link == key) {
XP_STX_AT(oaha, hash + 1
while (link != stx->nil) {
if (XP_STX_AT(stx,link,0) == key) return link;
link = XP_STX_AT(stx,link,2);
}
for (;;) {
if (link == stx->nil) {
new = xp_stx_new_link (stx, key, value);
}
return stx->nil; /* not found */
}
/*
if (XP_STX_AT(stx,link,0) == key) {
XP_STX_AT(stx,link,1) = value;
break;
}
void xp_stx_hash_insert (
xp_stx_t* stx, xp_stx_word_t table,
xp_stx_word_t hash, xp_stx_word_t key, xp_stx_word_t value)
{
xp_stx_word_t harr, link, next;
next = XP_STX_AT(stx,link,2);
if (next == stx->nil) {
new = xp_stx_new_link (stx, key, value);
XP_STX_AT(stx,link,2) = new;
break;
}
xp_assert (XP_STX_TYPE(stx,table) == XP_STX_INDEXED);
link = next;
*/
harr = XP_STX_AT(stx,table,0);
hash = link % XP_STX_SIZE(stx,table);
link = XP_STX_AT(stx,harr,hash);
if (link == stx->nil) {
new = xp_stx_new_link (stx, key, value);
XP_STX_AT(stx,harr,hash) = new;
}
else {
for (;;) {
if (XP_STX_AT(stx,link,0) == key) {
XP_STX_AT(stx,link,1) = value;
break;
}
next = XP_STX_AT(stx,link,2);
if (next == stx->nil) {
new = xp_stx_new_link (stx, key, value);
XP_STX_AT(stx,link,2) = new;
break;
}
link = next;
}
}
}

View File

@ -1,14 +1,25 @@
/*
* $Id: hash.h,v 1.1 2005-05-08 15:54:44 bacon Exp $
* $Id: hash.h,v 1.2 2005-05-10 06:02:19 bacon Exp $
*/
#ifndef _XP_STX_HASH_H_
#define _XP_STX_HASH_H_
#include <xp/stx/stx.h>
#ifdef __cplusplus
extern "C"
#endif
xp_stx_word_t xp_stx_new_link (
xp_stx_t* stx, xp_stx_word_t key, xp_stx_word_t value);
xp_stx_word_t xp_stx_hash_lookup (
xp_stx_t* stx, xp_stx_word_t table,
xp_stx_word_t hash, xp_stx_word_t key);
void xp_stx_hash_insert (
xp_stx_t* stx, xp_stx_word_t table,
xp_stx_word_t hash, xp_stx_word_t key, xp_stx_word_t value);
#ifdef __cplusplus
}
#endif

View File

@ -1,5 +1,5 @@
/*
* $Id: stx.h,v 1.5 2005-05-08 15:22:45 bacon Exp $
* $Id: stx.h,v 1.6 2005-05-10 06:02:19 bacon Exp $
*/
#ifndef _XP_STX_STX_H_
@ -30,8 +30,8 @@ typedef struct xp_stx_t xp_stx_t;
struct xp_stx_object_t
{
/* access - mode: 2; size: rest;
* mode - word indexed: 00 byte indexed: 01 char indexed: 10
/* access - type: 2; size: rest;
* type - word indexed: 00 byte indexed: 01 char indexed: 10
*/
xp_stx_word_t access;
xp_stx_word_t class;
@ -69,6 +69,7 @@ struct xp_stx_t
xp_stx_word_t nil;
xp_stx_word_t true;
xp_stx_word_t false;
xp_stx_word_t symbol_table;
xp_bool_t __malloced;
};
@ -85,16 +86,22 @@ struct xp_stx_t
#define XP_STX_STRING_OBJECT(mem,idx) \
((xp_stx_string_object_t*)((mem)->slots[idx]))
#define XP_STX_OBJECT_DATA(mem,idx) \
(((XP_STX_OBJECT_ACCESS(mem,idx) & 0x03) == 0x00)? \
((XP_STX_OBJECT_TYPE(mem,idx) == XP_STX_INDEXED)? \
(XP_STX_OBJECT(mem,idx)).data): \
(((XP_STX_OBJECT_ACCESS(mem,idx) & 0x03) == 0x01)? \
((XP_STX_OBJECT_TYPE(mem,idx) == XP_STX_BYTE_INDEXED)? \
(XP_STX_BYTE_OBJECT(mem,idx)).data): \
(XP_STX_STRING_OBJECT(mem,idx)).data))
*/
#define XP_STX_OBJECT(stx,idx) (((stx)->memory).slots[idx])
#define XP_STX_ACCESS(stx,idx) (XP_STX_OBJECT(stx,(idx))->access)
#define XP_STX_CLASS(stx,idx) (XP_STX_OBJECT(stx,(idx))->class)
#define XP_STX_ACCESS(stx,idx) (XP_STX_OBJECT(stx,(idx))->access)
#define XP_STX_TYPE(stx,idx) (XP_STX_ACCESS(stx,idx) & 0x03)
#define XP_STX_SIZE(stx,idx) (XP_STX_ACCESS(stx,idx) >> 0x02)
#define XP_STX_INDEXED (0x00)
#define XP_STX_BYTE_INDEXED (0x01)
#define XP_STX_CHAR_INDEXED (0x02)
#define XP_STX_AT(stx,idx,n) \
(((xp_stx_word_t*)(XP_STX_OBJECT(stx,idx) + 1))[n])