1 /* Copyright (c) 2012. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
8 import java.util.ArrayList;
11 * Stores the information held in a bucket
14 private ArrayList<Integer> nodes;
20 public Bucket(int id) {
21 this.nodes = new ArrayList<Integer>();
25 * Returns the bucket's id.
31 * Returns how many nodes there is in the bucket
37 * Returns if the bucket contains the element
39 public boolean contains(int id) {
40 return nodes.contains(id);
43 * Add an to the front of the bucket
45 public void add(int id) {
49 * Pushs an element into the front of a bucket.
51 public void pushToFront(int id) {
52 int i = nodes.indexOf(id);
59 public int getNode(int id) {
63 * Adds the content of the bucket into a answer object.
65 public void addToAnswer(Answer answer, int destination) {
66 for (int id : this.nodes) {
67 answer.getNodes().add(new Contact(id,id ^ destination));
72 public String toString() {
73 return "Bucket [id= " + id + " nodes=" + nodes + "]";