Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines with new year.
[simgrid.git] / examples / java / dht / kademlia / Answer.java
index 0a30cf6..28a9d4c 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2012-2018. The SimGrid Team.
+/* Copyright (c) 2012-2019. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -31,8 +31,9 @@ public class Answer {
     return nodes.size();
   }
 
-  public void remove(int index) {
-    nodes.remove(index);
+  public void trim() {
+    if (nodes.size() > Common.BUCKET_SIZE)
+      nodes.subList(nodes.size() - Common.BUCKET_SIZE, nodes.size()).clear();
   }
 
   public void add(Contact contact) {
@@ -51,9 +52,8 @@ public class Answer {
     }
     Collections.sort(nodes);
     //Trim the list
-    while (answer.size() > Common.BUCKET_SIZE) {
-      answer.remove(answer.size() - 1);
-    }
+    answer.trim();
+
     return nbAdded;
   }