コード例 #1
0
 public V put(K key, V value) {
   if (table == null || table.length == 0) {
     table = resize();
   }
   Node<K, V> p;
   int n = table.length, i, hash = hash(key);
   if ((p = table[i = (n - 1) & hash]) == null) {
     table[i] = new Node<>(hash, key, value, null);
   } else {
     while (true) {
       if (p.hash == hash && Objects.equals(p.key, key)) {
         V oldVal = p.value;
         p.value = value;
         return oldVal;
       }
       if (p.next == null) {
         break;
       }
       p = p.next;
     }
     p.next = new Node<>(hash, key, value, null);
   }
   if (++size == n) {
     table = resize();
   }
   return null;
 }
コード例 #2
0
ファイル: Queue.java プロジェクト: ablochha/Resume
 /**
  * Adds the item to this queue.
  *
  * @param item the item to add
  */
 public void enqueue(Item item) {
   Node<Item> oldlast = last;
   last = new Node<Item>();
   last.item = item;
   last.next = null;
   if (isEmpty()) first = last;
   else oldlast.next = last;
   N++;
 }
コード例 #3
0
 public boolean insert(T toInsert) {
   Node current = root;
   Node parent = null;
   while (current != null) {
     parent = current;
     if (less(toInsert, current.value)) current = current.left;
     else current = current.right;
   }
   current = new Node();
   current.value = toInsert;
   if (parent == null) return true;
   current.parent = parent;
   if (less(toInsert, parent.value)) parent.left = current;
   else parent.right = current;
   return true;
 }
コード例 #4
0
ファイル: TestGraph.java プロジェクト: datomnurdin/JADS
  public static void main(String[] args) throws WrongArchException {

    // Nodes Creation
    System.out.println("\nNodes Creation: ");

    Node<String> Q0 = new Node<String>("q0");
    System.out.println(" - Q0: " + Q0.toString());

    Node<String> Q1 = new Node<String>("q1");
    System.out.println(" - Q1: " + Q1.toString());

    Node<String> Q2 = new Node<String>("q2");
    System.out.println(" - Q2: " + Q2.toString());

    Node<String> Q3 = new Node<String>("q3");
    System.out.println(" - Q3: " + Q3.toString());

    Node<String> Q4 = new Node<String>("q4");
    System.out.println(" - Q4 " + Q4.toString());

    Node<String> Q5 = new Node<String>("q5");
    System.out.println(" - Q5 " + Q5.toString());

    Node<String> Q6 = new Node<String>("q6");
    System.out.println(" - Q6 " + Q6.toString());

    // Archs Creation
    System.out.println("\nArchs Creation: ");

    Arch<String> A00 = new Arch<String>(Q0, Q0, "1");
    System.out.println(" - A00: " + A00.toString());

    Arch<String> A01 = new Arch<String>(Q0, Q1, "0");
    System.out.println(" - A01: " + A01.toString());

    Arch<String> A10 = new Arch<String>(Q1, Q0, "1");
    System.out.println(" - A10: " + A10.toString());

    Arch<String> A11 = new Arch<String>(Q1, Q1, "0");
    System.out.println(" - A11: " + A11.toString());

    Arch<String> A12 = new Arch<String>(Q1, Q2, "1");
    System.out.println(" - A12: " + A12.toString());

    Arch<String> A34 = new Arch<String>(Q3, Q4, "0");
    System.out.println(" - A34: " + A34.toString());

    Arch<String> A45 = new Arch<String>(Q4, Q5, "1");
    System.out.println(" - A45: " + A45.toString());

    Arch<String> A53 = new Arch<String>(Q5, Q3, "0");
    System.out.println(" - A53: " + A53.toString());

    // ################################################################
    //			Graph Test
    // ################################################################

    System.out.println("\n");

    GraphOriented<String> G1 = new GraphOriented<String>("G1");

    try {

      G1.addNode(Q0);
      G1.addNode(Q1);
      G1.addNode(Q2);
      G1.addNode(Q3);
      G1.addNode(Q4);
      G1.addNode(Q5);
      G1.addNode(Q6);

      G1.addArch(A00);
      G1.addArch(A01);
      G1.addArch(A10);
      G1.addArch(A11);
      G1.addArch(A12);
      G1.addArch(A34);
      G1.addArch(A45);
      G1.addArch(A53);

      System.out.println("\n\n\nTO STRING:\n");

      System.out.println(G1.toString());

    } catch (GraphNotReadyException e) {

      e.printStackTrace();
    }
  }