예제 #1
0
 /**
  * Resets the tree values and state. All the values are set to Integer.MAX_VALUE and the states to
  * 0.
  */
 public void reset() {
   int k;
   // Set all values to Integer.MAX_VALUE
   // and states to 0
   for (k = lvls - 1; k >= 0; k--) {
     ArrayUtil.intArraySet(treeV[k], Integer.MAX_VALUE);
     ArrayUtil.intArraySet(treeS[k], 0);
   }
   // Invalidate saved tree
   saved = false;
 }
예제 #2
0
  @Override
  public int getId(
      @NotNull VirtualFile parent, @NotNull String childName, @NotNull NewVirtualFileSystem fs) {
    int parentId = getFileId(parent);
    int[] children = FSRecords.list(parentId);

    if (children.length > 0) {
      // fast path, check that some child has same nameId as given name, this avoid O(N) on
      // retrieving names for processing non-cached children
      int nameId = FSRecords.getNameId(childName);
      for (final int childId : children) {
        if (nameId == FSRecords.getNameId(childId)) {
          return childId;
        }
      }
      // for case sensitive system the above check is exhaustive in consistent state of vfs
    }

    for (final int childId : children) {
      if (namesEqual(fs, childName, FSRecords.getName(childId))) return childId;
    }

    final VirtualFile fake = new FakeVirtualFile(parent, childName);
    final FileAttributes attributes = fs.getAttributes(fake);
    if (attributes != null) {
      final int child = createAndFillRecord(fs, fake, parentId, attributes);
      FSRecords.updateList(parentId, ArrayUtil.append(children, child));
      return child;
    }

    return 0;
  }
예제 #3
0
 @NotNull
 private static String[] listPersisted(@NotNull int[] childrenIds) {
   String[] names = ArrayUtil.newStringArray(childrenIds.length);
   for (int i = 0; i < childrenIds.length; i++) {
     names[i] = FSRecords.getName(childrenIds[i]);
   }
   return names;
 }
예제 #4
0
  private static void removeIdFromParentList(
      final int parentId, final int id, @NotNull VirtualFile parent, VirtualFile file) {
    int[] childList = FSRecords.list(parentId);

    int index = ArrayUtil.indexOf(childList, id);
    if (index == -1) {
      throw new RuntimeException(
          "Cannot find child ("
              + id
              + ")"
              + file
              + "\n\tin ("
              + parentId
              + ")"
              + parent
              + "\n\tactual children:"
              + Arrays.toString(childList));
    }
    childList = ArrayUtil.remove(childList, index);
    FSRecords.updateList(parentId, childList);
  }
  private boolean[][] getExclusiveMutations(Set<String> g1, Set<String> g2) {
    boolean[][] b = new boolean[2][];

    b[0] = getMutated(g1);
    b[1] = getMutated(g2);

    System.out.println("b[0].length = " + b[0].length);
    System.out.println("M1 = " + ArrayUtil.countValue(b[0], true));
    System.out.println("M2 = " + ArrayUtil.countValue(b[1], true));

    for (int i = 0; i < b[0].length; i++) {
      if (b[0][i] && b[1][i]) {
        b[0][i] = false;
        b[1][i] = false;
      }
    }

    System.out.println("After removing overlaps:");
    System.out.println("M1 = " + ArrayUtil.countValue(b[0], true));
    System.out.println("M2 = " + ArrayUtil.countValue(b[1], true));
    return b;
  }
예제 #6
0
 /**
  * Creates a tag tree encoder with 'w' elements along the horizontal dimension and 'h' elements
  * along the vertical direction. The total number of elements is thus 'vdim' x 'hdim'.
  *
  * <p>The values of all elements are initialized to Integer.MAX_VALUE.
  *
  * @param h The number of elements along the horizontal direction.
  * @param w The number of elements along the vertical direction.
  */
 public TagTreeEncoder(int h, int w) {
   int k;
   // Check arguments
   if (w < 0 || h < 0) {
     throw new IllegalArgumentException();
   }
   // Initialize elements
   init(w, h);
   // Set values to max
   for (k = treeV.length - 1; k >= 0; k--) {
     ArrayUtil.intArraySet(treeV[k], Integer.MAX_VALUE);
   }
 }
예제 #7
0
 /**
  * Resets the tree values and state. The values are set to the values in 'val'. The states are all
  * set to 0.
  *
  * @param val The new values for the leafs, in lexicographical order.
  */
 public void reset(int val[]) {
   int k;
   // Set values for leaf level
   for (k = w * h - 1; k >= 0; k--) {
     treeV[0][k] = val[k];
   }
   // Calculate values at other levels
   recalcTreeV();
   // Set all states to 0
   for (k = lvls - 1; k >= 0; k--) {
     ArrayUtil.intArraySet(treeS[k], 0);
   }
   // Invalidate saved tree
   saved = false;
 }
  @NotNull
  public static String[] filterNames(@NotNull String[] names) {
    int filteredCount = 0;
    for (String string : names) {
      if (isBadName(string)) filteredCount++;
    }
    if (filteredCount == 0) return names;

    String[] result = ArrayUtil.newStringArray(names.length - filteredCount);
    int count = 0;
    for (String string : names) {
      if (isBadName(string)) continue;
      result[count++] = string;
    }

    return result;
  }
예제 #9
0
 private static void appendIdToParentList(final int parentId, final int childId) {
   int[] childrenList = FSRecords.list(parentId);
   childrenList = ArrayUtil.append(childrenList, childId);
   FSRecords.updateList(parentId, childrenList);
 }