Package net.myrrix.common.collection

Examples of net.myrrix.common.collection.FastIDSet$KeyIterator


    }, reloadMinutes, reloadMinutes, TimeUnit.MINUTES);
    doLoad();
  }
 
  private void doLoad() {
    FastIDSet newIDs = new FastIDSet();
    // Load something into it
    newIDs.add(1L);
    // ...
    someCurrentIDs = newIDs;
  }
View Full Code Here


  private final ReadWriteLock itemClustersLock;
 
  public Generation(FastByIDMap<FastIDSet> knownItemIDs,
                    FastByIDMap<float[]> X,
                    FastByIDMap<float[]> Y) {
    this(knownItemIDs, X, Y, new FastIDSet(1000), new FastIDSet(1000));
  }
View Full Code Here

    FastByIDMap<FastIDSet> knownItemIDs = generation.getKnownItemIDs();
    if (knownItemIDs == null && !considerKnownItems) {
      throw new UnsupportedOperationException("Can't ignore known items because no known items available");
    }
    FastIDSet usersKnownItemIDs = null;
    if (!considerKnownItems) {
      Lock knownItemLock = generation.getKnownItemLock().readLock();
      knownItemLock.lock();
      try {
        for (long userID : userIDs) {
          FastIDSet theKnownItemIDs = knownItemIDs.get(userID);
          if (theKnownItemIDs == null) {
            continue;
          }
          if (usersKnownItemIDs == null) {
            usersKnownItemIDs = theKnownItemIDs;
          } else {
            LongPrimitiveIterator it = usersKnownItemIDs.iterator();
            while (it.hasNext()) {
              if (!theKnownItemIDs.contains(it.nextLong())) {
                it.remove();
              }
            }
          }
          if (usersKnownItemIDs.isEmpty()) {
View Full Code Here

    Preconditions.checkArgument(howMany > 0, "howMany must be positive");

    float[] anonymousUserFeatures = buildAnonymousUserFeatures(itemIDs, values);

    FastIDSet userKnownItemIDs = new FastIDSet(itemIDs.length);
    for (long itemID : itemIDs) {
      userKnownItemIDs.add(itemID);
    }

    float[][] anonymousFeaturesAsArray = { anonymousUserFeatures };

    Generation generation = getCurrentGeneration();   
View Full Code Here

    FastByIDMap<FastIDSet> knownItemIDs = generation.getKnownItemIDs();
    if (knownItemIDs == null) {
      throw new UnsupportedOperationException();
    }

    FastIDSet itemTagIDs = generation.getItemTagIDs();
    FastByIDFloatMap itemCounts = new FastByIDFloatMap();   
    Lock knownItemReadLock = generation.getKnownItemLock().readLock();
    knownItemReadLock.lock();
    try {
        // Don't count data from users that are really item tags
        Lock xReadLock = generation.getXLock().readLock();
        xReadLock.lock();
        try {
         
          for (FastByIDMap.MapEntry<FastIDSet> entry : generation.getKnownItemIDs().entrySet()) {
            long userID = entry.getKey();
            if (!itemTagIDs.contains(userID)) {
              FastIDSet itemIDs = entry.getValue();
              synchronized (itemIDs) {
                LongPrimitiveIterator it = itemIDs.iterator();
                while (it.hasNext()) {
                  long itemID = it.nextLong();
                  itemCounts.increment(itemID, 1.0f);
                }
              }
            }
          }
         
        } finally {
          xReadLock.unlock();
        }
    } finally {
      knownItemReadLock.unlock();
    }
   
    // Filter out 'items' that were really user tags
    FastIDSet userTagIDs = generation.getUserTagIDs();
    Lock yReadLock = generation.getYLock().readLock();
    yReadLock.lock();
    try {
      LongPrimitiveIterator it = itemCounts.keySetIterator();
      while (it.hasNext()) {
        if (userTagIDs.contains(it.nextLong())) {
          it.remove();
        }
      }
    } finally {
      yReadLock.unlock();
View Full Code Here

    updateFeatures(userFeatures, itemFeatures, value, generation);

    FastByIDMap<FastIDSet> knownItemIDs = generation.getKnownItemIDs();
    if (knownItemIDs != null) {
      FastIDSet userKnownItemIDs;
      ReadWriteLock knownItemLock = generation.getKnownItemLock();
      Lock knownItemReadLock = knownItemLock.readLock();
      knownItemReadLock.lock();
      try {
        userKnownItemIDs = knownItemIDs.get(userID);
        if (userKnownItemIDs == null) {
          userKnownItemIDs = new FastIDSet();
          Lock knownItemWriteLock = knownItemLock.writeLock();
          knownItemReadLock.unlock();
          knownItemWriteLock.lock();
          try {
            knownItemIDs.put(userID, userKnownItemIDs);
          } finally {
            knownItemReadLock.lock();
            knownItemWriteLock.unlock();
          }
        }
      } finally {
        knownItemReadLock.unlock();
      }

      synchronized (userKnownItemIDs) {
        userKnownItemIDs.add(itemID);
      }
    }
   
    updateClusters(userID, userFeatures, generation.getUserClusters(), generation.getUserClustersLock().readLock());
    updateClusters(itemID, itemFeatures, generation.getItemClusters(), generation.getItemClustersLock().readLock());
View Full Code Here

   
    if (closestCentroid == null) {
      return;
    }

    FastIDSet newMembers = closestCentroid.getMembers();
   
    boolean removeFromCurrentCluster;       
    synchronized (newMembers) {
      // Wasn't already present, so was present elsewhere; find and remove it       
      removeFromCurrentCluster = newMembers.add(id);
    }
   
    if (removeFromCurrentCluster) {
      clustersReadLock.lock();
      try {
        for (IDCluster cluster : clusters) {
          FastIDSet oldMembers = cluster.getMembers();
          synchronized (oldMembers) {
            if (oldMembers.remove(id)) {
              break;
            }
          }
        }
      } finally {
View Full Code Here

    boolean removeUser = false;
    FastByIDMap<FastIDSet> knownItemIDs = generation.getKnownItemIDs();
    if (knownItemIDs != null) {

      Lock knownItemReadLock = knownItemLock.readLock();
      FastIDSet userKnownItemIDs;
      knownItemReadLock.lock();
      try {
        userKnownItemIDs = knownItemIDs.get(userID);
      } finally {
        knownItemReadLock.unlock();
      }

      if (userKnownItemIDs == null) {
        // Doesn't exist? So ignore this request
        return;
      }

      synchronized (userKnownItemIDs) {
        if (!userKnownItemIDs.remove(itemID)) {
          // Item unknown, so ignore this request
          return;
        }
        removeUser = userKnownItemIDs.isEmpty();
      }
    }

    // We can proceed with the request
View Full Code Here

      return;
    }
   
    long tagID = tagHasher.toLongID(tag);   
   
    FastIDSet userTagIDs = generation.getUserTagIDs();
    Lock userTagWriteLock = generation.getYLock().writeLock();
    userTagWriteLock.lock();
    try {
      userTagIDs.add(tagID);
    } finally {
      userTagWriteLock.unlock();
    }

    float[] userFeatures = getFeatures(userID, generation.getX(), generation.getXLock());
View Full Code Here

      return;
    }

    long tagID = tagHasher.toLongID(tag);
   
    FastIDSet itemTagIDs = generation.getItemTagIDs();
    Lock itemTagWriteLock = generation.getXLock().writeLock();
    itemTagWriteLock.lock();
    try {
      itemTagIDs.add(tagID);
    } finally {
      itemTagWriteLock.unlock();
    }
   
    float[] tagFeatures = getFeatures(tagID, generation.getX(), generation.getXLock());
View Full Code Here

TOP

Related Classes of net.myrrix.common.collection.FastIDSet$KeyIterator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.