コード例 #1
0
ファイル: EdgeIndex.java プロジェクト: szarnyasg/corese
  public boolean exist(Entity edge) {
    if (index != IGRAPH && edge.nbNode() <= index) {
      // use case:  additional node is not present, do not index on this node
      // never happens for subject object and graph
      return false;
    }
    List<Entity> list = getByLabel(edge);
    if (list == null) return false;
    int i = find(list, edge, 0, list.size());

    if (i >= list.size()) {
      return false;
    }

    int res = comp.compare(edge, list.get(i));
    return (res == 0);
  }
コード例 #2
0
ファイル: EdgeIndex.java プロジェクト: szarnyasg/corese
  public Entity delete(Entity edge) {
    if (index != IGRAPH && edge.nbNode() <= index) {
      // use case:  additional node is not present, do not index on this node
      // never happens for subject object and graph
      return null;
    }
    List<Entity> list = getByLabel(edge);
    if (list == null) return null;

    Comparator<Entity> cmp = getComp();

    int i = find(cmp, list, edge, 0, list.size());

    if (i >= list.size()) {
      return null;
    }

    if (graph.hasTag()) {
      // if edge have no tag:
      // dichotomy may have jump in the middle of the tag list
      // find first edge of the list
      while (i > 0 && cmp.compare(list.get(i - 1), edge) == 0) {
        i--;
      }
    }

    Entity ent = delete(cmp, edge, list, i);

    logDelete(ent);

    if (graph.hasTag()) {
      // delete all occurrences of triple that match edge
      // with different tags
      Entity res = ent;
      while (i < list.size() && res != null) {
        res = delete(cmp, edge, list, i);
        logDelete(res);
      }
    }
    return ent;
  }
コード例 #3
0
ファイル: EdgeIndex.java プロジェクト: szarnyasg/corese
 /**
  * Create the index of property pred on nth argument It is synchronized on pred hence several
  * synGetCheck can occur in parallel on different pred
  */
 private List<Entity> synCheckGet(Node pred) {
   synchronized (pred) {
     ArrayList<Entity> list = get(pred);
     if (list != null && list.size() == 0) {
       List<Entity> std = (List<Entity>) graph.getIndex().getEdges(pred, null);
       list.ensureCapacity(std.size());
       if (index < 2) {
         // we are sure that there are at least 2 nodes
         list.addAll(std);
       } else
         for (Entity ent : std) {
           // if additional node is missing: do not index this edge
           if (ent.nbNode() > index) {
             list.add(ent);
           }
         }
       index(pred);
     }
     return list;
   }
 }
コード例 #4
0
ファイル: EdgeIndex.java プロジェクト: szarnyasg/corese
  /** noGraph == true => if edge already exists in another graph, do not add edge */
  public Entity add(Entity edge, boolean duplicate) {
    if (index != IGRAPH && edge.nbNode() <= index) {
      // use case:  additional node is not present, do not index on this node
      // never happens for subject object and graph
      return null;
    }

    List<Entity> list = define(edge.getEdge().getEdgeNode());

    Comparator cc = comp;

    boolean needTag = index == 0 && graph.needTag(edge);
    if (needTag) {
      // this edge has no tag yet and it will need onefind
      // let's see if there is the same triple (with another tag)
      // in this case, we skip the insertion
      // otherwise we tag the triple and we insert it
      cc = skipTag;
    } else if (!duplicate) {
      cc = skipGraph;
    }

    if (isSort(edge)) {
      // edges are sorted, check presence by dichotomy
      int i = find(cc, list, edge, 0, list.size());
      int res = 0;

      if (i >= list.size()) {
        i = list.size();
      } else {
        if (index == 0) {
          res = cc.compare(edge, list.get(i));
          if (res == 0) {
            // eliminate duplicate at load time for index 0
            count++;
            return null;
          }
        }
      }

      if (needTag) {
        tag(edge);
      }

      if (onInsert(edge)) {
        list.add(i, edge);
        logInsert(edge);
      } else {
        return null;
      }

    } else {
      // edges are not already sorted (load time)
      // add all edges, duplicates will be removed later when first query occurs
      if (onInsert(edge)) {
        list.add(edge);
        logInsert(edge);
      } else {
        return null;
      }
    }

    // complete(edge);
    return edge;
  }