<commit_before>/**
 * 
 */
package se.sics.mspsim.net;

import java.util.Vector;
import se.sics.mspsim.util.Utils;

/**
 * @author joakim
 *
 */
public class NeighborTable {
  // currently supports max 64 neighbors...
  Neighbor[] neighbors = new Neighbor[64];
  int neighborCount = 0;
  
  Neighbor defrouter;
  
  public synchronized Neighbor addNeighbor(byte[] ipAddress, byte[] linkAddress) {
    Neighbor nb = new Neighbor();
    nb.ipAddress = ipAddress;
    nb.linkAddress = linkAddress;
    nb.state = Neighbor.INCOMPLETE;
    neighbors[neighborCount++] = nb;
    return nb;
  }
  
  public Neighbor getDefrouter() {
    return defrouter;
  }
  
  public void setDefrouter(Neighbor neighbor) {
    defrouter = neighbor;
  }
  
  public synchronized boolean removeNeighbor(Neighbor nb) {
    for (int i = 0; i < neighborCount; i++) {
      if (nb == neighbors[i]) {
        // move last element forward to this position...
        neighbors[i] = neighbors[neighborCount - 1];
        neighborCount--;
        return true;<commit_msg>handle update of existing neighbors<commit_after>/**
 * 
 */
package se.sics.mspsim.net;
import se.sics.mspsim.util.Utils;

/**
 * @author joakim
 *
 */
public class NeighborTable {
  // currently supports max 64 neighbors...
  Neighbor[] neighbors = new Neighbor[64];
  int neighborCount = 0;
  
  Neighbor defrouter;
  
  public synchronized Neighbor addNeighbor(byte[] ipAddress, byte[] linkAddress) {
    Neighbor nb = getNeighbor(ipAddress);
    if (nb == null) {
      nb = new Neighbor();
      nb.ipAddress = ipAddress;
      nb.linkAddress = linkAddress;
      nb.state = Neighbor.INCOMPLETE;
      if (neighborCount < neighbors.length) {
        neighbors[neighborCount++] = nb;
      } else {
        // TODO select suitable neighbor to replace
        neighbors[0] = nb;
      }
    } else {
      /* Neighbor already in neighbor table */
      nb.linkAddress = linkAddress;
      nb.state = Neighbor.INCOMPLETE;
    }
    return nb;
  }
  
  public Neighbor getDefrouter() {
    return defrouter;
  }
  
  public void setDefrouter(Neighbor neighbor) {
    defrouter = neighbor;
  }
  
  public synchronized boolean removeNeighbor(Neighbor nb) {
    for (int i = 0; i < neighborCount; i++) {
      if (nb == neighbors[i]) {
        // move last element forward to this position...
        neighbors[i] = neighbors[neighborCount - 1];
        neighborCount--;
        return true;
{'fraction_non_alphanumeric': 0.11271081859317153, 'fraction_numerical': 0.006170300287947347, 'mean_word_length': 2.673716012084592, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4922978', 'n_tokens_mistral': 770, 'n_tokens_neox': 762, 'n_words': 200}