📄 hash.cpp
字号:
/* * Copyright (C) 2006, Binary Ma * Licence: GNU GPL 1991 - version 2 * Bug report: binary@eniak.org*/#include "hash.h"#include <search.h>#include <stdlib.h>#include <string.h>static const char* VERSION = "0.4.1";bool hash::init = false;hash::hash( size_t max ){ error = -1; if( init ) return; error = 0; head.next = NULL; point = &head; init = hcreate( max );}hash::~hash(){ if( !init || error ) return; hdestroy(); struct _hash_chains* save = head.next; while( NULL != ( point = save ) ) { free( point->ent.key ); free( point->ent.data ); save = point->next; delete point; }}ENTRY* hash::search( const char* key ){ if( !init || NULL == key ) return NULL; ENTRY ent; ent.key = (char*)key; ent.data = NULL; return hsearch( ent, FIND );}int hash::insert( ENTRY ent, size_t size ){ if( !init || error || NULL == ent.key ) return -__LINE__; point->next = new struct _hash_chains; point = point->next; point->next = NULL; point->ent.key = strdup( ent.key ); ent.key = point->ent.key; point->ent.data = NULL; if( NULL != ent.data ); { point->ent.data = malloc( size ); memcpy( point->ent.data, ent.data, size ); ent.data = point->ent.data; } return !hsearch( ent, ENTER );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -