/*____________________________________________________________________________
dictionary, words and their definition
____________________________________________________________________________*/

#pragma once
#ifndef _DICT
#define _DICT

#include "word.h"
/*____________________________________________________________________________
class
____________________________________________________________________________*/

//association list
//binary tree
//complexity

class dict{
    word _key,                      //key word associated with element
         * _value;                  //value containing key
    dict * _next;                   //chaining value in a linked list way
public:
    dict();                         //constructor, default, create sentinel
    dict(dict * , word, word *);    //constructor, with key and value
    //getter
    word key()const;                //return key
    const word * value()const;      //return value
    const dict * at(int)const;      //return dict at given pos
    const word * find(word)const;   //return value associated with given key, 0 if fail
};

/*____________________________________________________________________________
method
____________________________________________________________________________*/

dict::dict()
{
    _key = 0;
    _value = 0;
    _next = 0;
}

dict::dict(dict * next, word key, word * value)
{
    _next = next;
    _key = key;
    _value = value;
}

//getter
word dict::key()const
{
    return _key;
}

const word * dict::value()const
{
    return _value;
}

const dict * dict::at(int index)const
{
    if (index)
        if (_next)
            return _next->at(index-1);
        else
            return 0;
    return this;
}

const word * dict::find(word key)const
{
    if (key == _key)
        return _value;
    else if (_next)
        return _next->find(key);
    return 0;
}



#endif
