본문 바로가기

Programming/DS SorceCode

HashRecord.h : 해시 맵을 위한 keyed Record 클래스

#pragma once

#ifndef ___HashRecord

#define ___HashRecord

// HashRecord.h : 해시 맵을 위한 keyed Record 클래스

#include <cstdio>

#include <string>

#include <cstring>

using namespace std;

#define KEY_SIZE 64 // 탐색키의 최대길이

#define VALUE_SIZE 64 // 탐색키와 관련된 정보


class Record {

char key[KEY_SIZE]; // 키 필드(사전의 경우 "단어")

char value[VALUE_SIZE]; // 키와 관련된 자료 ("의미")

public:

Record(const char* k = "", const char*v = "") { set(k, v); }

void set(const char* k, const char* v = "") {

strcpy_s(key, k);

strcpy_s(value, v);

}

void reset() { set("", ""); }

bool isEmpty() { return key[0] == '\0'; }

bool equal(const char* k) { return strcmp(k, key) == 0; }

string getKey(int i) { return key; }

string getValue(int i) { return value; }

void display() { printf("%20s = %s\n", key, value); }

};

#endif // !___HashRecord