package modules.hashtable;

import utils.*;
import modules.neighborset.*;
import modules.gradient.*;
import simulator.*;
import java.util.*;

// rests on the PersistentNode and PNHierarchy modules

// Duties:
// 1. maintain hashtables
// 2. create nodes which follow the hash to the leaves
// 3. dispatch READ/WRITE events to the nodes
// 4. garbage collection [not implemented]

// centers of nodes spread the hash function

public class HashTable implements ProcessorModule {
  PortedProcessor pp; ActiveGradient ag; NeighborSet ns;

  public Symbol getName() { return Symbol.GetSymbol("Hashtable"); }
  public void link(PortedProcessor p) {
    pp = p;
    ag = (ActiveGradient)p.getModule("ActiveGradient");
    ns = (NeighborSet)pp.getModule("NeighborSet");
    pp.addClockListener(this);
  }
  public void init() {
  }
  public boolean signalEvent(Symbol name,Object data) {
    boolean changed = false;
    if(name==PortedProcessor.kClock) {
      //      maintainhashtables();
      
    }
    return changed;
  }

  public String toString() { return "Hashtable"; }

  /*

  // public interface
  public void put(Object key, Object value, DelayedReturn.Object ack) {
    sendOperation(WRITE,key,value);
  }
  public void get(Object key, DelayedReturn.Object r) {
    sendOperation(READ,key,value);
  }

  private void processOperation() {
    // if op key is in the local-table, run the op
    // otherwise take a step towards it
  }

  */

}

/*
  How does the Hashtable work?
  Read: send a ping in & wait for its response --- repeat every n ticks
  Write: read, then send a write, then read again: ack when the value
  becomes changed
  The key question is the Unify step:
  

*/
