Instantiates an on-heap UpdateSketch from Memory.
@param srcMem <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
@param seed <a href="{@docRoot}/resources/dictionary.html#seed">See Update Hash Seed</a>.
@return an UpdateSketch
435916
public static UpdateSketch heapify(final Memory srcMem, final long seed) {
    final Family family = Family.idToFamily(srcMem.getByte(FAMILY_BYTE));
    if (family.equals(Family.ALPHA)) {
      return HeapAlphaSketch.heapifyInstance(srcMem, seed);
    }
    return HeapQuickSelectSketch.heapifyInstance(srcMem, seed);
  }
1334518
@SuppressWarnings("unchecked")
	protected boolean triggerRefreshIfNeeded(final Element e){
		if (refreshAheadNeeded(e.getLastAccessTime(), e.getCreationTime(), e.getExpirationTime())){
			// to apply a simple and not strict concurrency locking
			final long signature = Thread.currentThread().getId() * 1000000L + (System.currentTimeMillis() % 1000000L);
			if (e.getVersion() == 1){	// 1 is the default value of version field
				e.setVersion(signature);
				if (e.getVersion() == signature){	// double check
					threadPool.execute(new Runnable(){
						public void run(){
							if (e.getVersion() == signature){	// triple check
								try{
									V newValue = getDirectly((K)e.getObjectKey());
									if (newValue == null){
										cache.remove(e.getObjectKey());
									}else{
										cache.put(new Element((K)e.getObjectKey(), newValue));
									}
								}catch(Exception ex){
									logger.warn("Failed to update the value associated with specified key '{}' in cache '{}'", e.getObjectKey(), cache.getName(), ex);
								}
							}
						}
					});
					return true;
				}
			}
		}
		return false;
	}
313658
public static void createPatch( String oldPath, String newPath, OutputStream os, boolean minimal )
            throws IOException
    {
        JarFile2 oldJar = new JarFile2( oldPath );
        JarFile2 newJar = new JarFile2( newPath );

        try
        {
            Iterator entries;
            HashMap moved = new HashMap();
            HashSet visited = new HashSet();
            HashSet implicit = new HashSet();
            HashSet moveSrc = new HashSet();
            HashSet newEntries = new HashSet();

            // FIRST PASS
            // Go through the entries in new jar and
            // determine which files are candidates for implicit moves
            // ( files that has the same filename and same content in old.jar
            // and new.jar )
            // and for files that cannot be implicitly moved, we will either
            // find out whether it is moved or new (modified)
            entries = newJar.getJarEntries();
            if ( entries != null )
            {
                while ( entries.hasNext() )
                {
                    JarEntry newEntry = (JarEntry) entries.next();
                    String newname = newEntry.getName();

                    // Return best match of contents, will return a name match if possible
                    String oldname = oldJar.getBestMatch( newJar, newEntry );
                    if ( oldname == null )
                    {
                        // New or modified entry
                        if ( _debug )
                        {
                            System.out.println( "NEW: " + newname );
                        }
                        newEntries.add( newname );
                    }
                    else
                    {
                        // Content already exist - need to do a move

                        // Should do implicit move? Yes, if names are the same, and
                        // no move command already exist from oldJar
                        if ( oldname.equals( newname ) && !moveSrc.contains( oldname ) )
                        {
                            if ( _debug )
                            {
                                System.out.println( newname + " added to implicit set!" );
                            }
                            implicit.add( newname );
                        }
                        else
                        {
                            // The 1.0.1/1.0 JarDiffPatcher cannot handle
                            // multiple MOVE command with same src.
                            // The work around here is if we are going to generate
                            // a MOVE command with duplicate src, we will
                            // instead add the target as a new file.  This way
                            // the jardiff can be applied by 1.0.1/1.0
                            // JarDiffPatcher also.
                            if ( !minimal && ( implicit.contains( oldname ) || moveSrc.contains( oldname ) ) )
                            {

                                // generate non-minimal jardiff
                                // for backward compatibility

                                if ( _debug )
                                {
                                    System.out.println( "NEW: " + newname );
                                }
                                newEntries.add( newname );
                            }
                            else
                            {
                                // Use newname as key, since they are unique
                                if ( _debug )
                                {
                                    System.err.println( "moved.put " + newname + " " + oldname );
                                }
                                moved.put( newname, oldname );
                                moveSrc.add( oldname );
                            }
                            // Check if this disables an implicit 'move <oldname> <oldname>'
                            if ( implicit.contains( oldname ) && minimal )
                            {

                                if ( _debug )
                                {
                                    System.err.println( "implicit.remove " + oldname );

                                    System.err.println( "moved.put " + oldname + " " + oldname );
                                }
                                implicit.remove( oldname );
                                moved.put( oldname, oldname );
                                moveSrc.add( oldname );
                            }


                        }
                    }
                }
            } //if (entries != null)

            // SECOND PASS: <deleted files> = <oldjarnames> - <implicitmoves> -
            // <source of move commands> - <new or modified entries>
            ArrayList deleted = new ArrayList();
            entries = oldJar.getJarEntries();
            if ( entries != null )
            {
                while ( entries.hasNext() )
                {
                    JarEntry oldEntry = (JarEntry) entries.next();
                    String oldName = oldEntry.getName();
                    if ( !implicit.contains( oldName ) && !moveSrc.contains( oldName ) &&
                            !newEntries.contains( oldName ) )
                    {
                        if ( _debug )
                        {
                            System.err.println( "deleted.add " + oldName );
                        }
                        deleted.add( oldName );
                    }
                }
            }

            //DEBUG
            if ( _debug )
            {
                //DEBUG:  print out moved map
                entries = moved.keySet().iterator();
                if ( entries != null )
                {
                    System.out.println( "MOVED MAP!!!" );
                    while ( entries.hasNext() )
                    {
                        String newName = (String) entries.next();
                        String oldName = (String) moved.get( newName );
                        System.out.println( "key is " + newName + " value is " + oldName );
                    }
                }

                //DEBUG:  print out IMOVE map
                entries = implicit.iterator();
                if ( entries != null )
                {
                    System.out.println( "IMOVE MAP!!!" );
                    while ( entries.hasNext() )
                    {
                        String newName = (String) entries.next();
                        System.out.println( "key is " + newName );
                    }
                }
            }

            JarOutputStream jos = new JarOutputStream( os );

            // Write out all the MOVEs and REMOVEs
            createIndex( jos, deleted, moved );

            // Put in New and Modified entries
            entries = newEntries.iterator();
            if ( entries != null )
            {

                while ( entries.hasNext() )
                {
                    String newName = (String) entries.next();
                    if ( _debug )
                    {
                        System.out.println( "New File: " + newName );
                    }
                    writeEntry( jos, newJar.getEntryByName( newName ), newJar );
                }
            }

            jos.finish();
            jos.close();

        }
        catch ( IOException ioE )
        {
            throw ioE;
        }
        finally
        {
            try
            {
                oldJar.getJarFile().close();
            }
            catch ( IOException e1 )
            {
                //ignore
            }
            try
            {
                newJar.getJarFile().close();
            }
            catch ( IOException e1 )
            {
                //ignore
            }
        } // finally
    }
442880
public static HashFunction[] createHashFunctions(final int seed,
            final int num) {
        final HashFunction[] hashFunctions = new HashFunction[num];
        for (int i = 0; i < num; i++) {
            hashFunctions[i] = Hashing.murmur3_128(seed + i);
        }
        return hashFunctions;
    }
30806
public function setSeed($seed)
    {
        if (is_int($seed) !== true) {
            throw new Exception(
                sprintf('The type of the seed value "%s" need to be int. You passed a(n) "%s".', $seed, gettype($seed))
            );
        }

        // We need to call different methods depending on chosen source
        switch ($this->getMode()) {

            case self::MODE_PHP_MERSENNE_TWISTER:
                mt_srand($seed);
                break;

            case self::MODE_PHP_DEFAULT:
                srand($seed);
                break;

            case self::MODE_OPEN_SSL:
            default:
                // Intentionally left blank
                break;
        }

        $this->seed = $seed;
    }
1133516
private HeapState processHeapStateCreation(final ConnectedResponse result, final String heapUri) {
        if (!subTermLock.isHeldByCurrentThread()) {
            throw new IllegalStateException("You must have the subTermLock before calling this method");
        }
        final HeapState newState = new HeapState(result.getHeap());
        // we're safe to lock this out of normal order as the HeapState isn't visible to other threads until the
        // end of this block. We have to have the lock before we make it visible..
        newState.getUpdateLock().lock();
        // new heap for this transport
        UpdateProducingHeapListener listener = new UpdateProducingHeapListener() {

            @Override
            protected void doUpdate(Update u) {
                if (u.getActions().size() > 0) {
                    newState.getQueuedChanges().add(new QueuedHeapChange(u));
                    // bad luck, we just added the heap and it's just about to get terminated...
                    if (u.getActions().contains(TerminateHeap.INSTANCE)) {
                        newState.getQueuedChanges().add(new HeapTermination());
                    }
                    heapsWaitingForUpdate.add(heapUri);
                }
            }
        };
        newState.setHeapListener(listener);
        result.getHeap().addListener(listener, false);
        heapStates.put(heapUri, newState);
        heapUris.put(newState.getHeapId(), heapUri);
        return newState;
    }
134882
public void putMemory(final WritableMemory dstMem, final ArrayOfItemsSerDe<T> serDe) {
    final byte[] byteArr = toByteArray(serDe);
    final long memCap = dstMem.getCapacity();
    if (memCap < byteArr.length) {
      throw new SketchesArgumentException(
          "Destination Memory not large enough: " + memCap + " < " + byteArr.length);
    }
    dstMem.putByteArray(0, byteArr, 0, byteArr.length);
  }
216854
public void shuffle(long seed) {
        // just skip shuffle if there's only 1 example
        if (numExamples() < 2)
            return;

        //note here we use the same seed with different random objects guaranteeing same order

        List<INDArray> arrays = new ArrayList<>();
        List<int[]> dimensions = new ArrayList<>();

        arrays.add(getFeatures());
        dimensions.add(ArrayUtil.range(1, getFeatures().rank()));

        arrays.add(getLabels());
        dimensions.add(ArrayUtil.range(1, getLabels().rank()));

        if (featuresMask != null) {
            arrays.add(getFeaturesMaskArray());
            dimensions.add(ArrayUtil.range(1, getFeaturesMaskArray().rank()));
        }

        if (labelsMask != null) {
            arrays.add(getLabelsMaskArray());
            dimensions.add(ArrayUtil.range(1, getLabelsMaskArray().rank()));
        }

        Nd4j.shuffle(arrays, new Random(seed), dimensions);

        //As per CpuNDArrayFactory.shuffle(List<INDArray> arrays, Random rnd, List<int[]> dimensions) and libnd4j transforms.h shuffleKernelGeneric
        if (exampleMetaData != null) {
            int[] map = ArrayUtil.buildInterleavedVector(new Random(seed), numExamples());
            ArrayUtil.shuffleWithMap(exampleMetaData, map);
        }
    }
474374
public void update(final byte[] key, final double[] values) {
    if (key == null || key.length == 0) { return; }
    insertOrIgnore(MurmurHash3.hash(key, seed_)[0] >>> 1, values);
  }
1218728
public static SingleItemSketch create(final byte[] data) {
    if ((data == null) || (data.length == 0)) { return null; }
    return new SingleItemSketch(hash(data, DEFAULT_UPDATE_SEED)[0] >>> 1);
  }
283991
public static void seed(long seed) {
        System.out.println("SEED="+seed);
        Prng.seed = seed;
        curRandom.setSeed(seed);
    }
628622
public static final ISID createRandom (final long seed) {

        // TODO: Implement Qualifier
        final Random rand = new Random(seed);

        final ISID isid = new ISID(Format.RANDOM, Constants.RESERVED_BYTE, (short) rand.nextInt(), (byte) rand.nextInt(), (short) 0);

        return isid;
    }
1086645
@Override
	public BrownianMotionInterface getCloneWithModifiedSeed(int seed) {
		return new BrownianBridge(timeDiscretization, numberOfPaths, seed, start, end);
	}
32030
public static ByteRangeRandomizer aNewByteRangeRandomizer(final Byte min, final Byte max, final long seed) {
        return new ByteRangeRandomizer(min, max, seed);
    }
1088010
public static <S extends Summary> Sketch<S> heapifySketch(final Memory mem,
      final SummaryDeserializer<S> deserializer) {
    final SerializerDeserializer.SketchType sketchType = SerializerDeserializer.getSketchType(mem);
    if (sketchType == SerializerDeserializer.SketchType.QuickSelectSketch) {
      return new QuickSelectSketch<S>(mem, deserializer, null);
    }
    return new CompactSketch<S>(mem, deserializer);
  }
992126
public HttpPatch createPatchMethod(final String path, final String sparqlUpdate) throws FedoraException {
        if ( isBlank(sparqlUpdate) ) {
            throw new FedoraException("SPARQL Update command must not be blank");
        }

        final HttpPatch patch = new HttpPatch(repositoryURL + path);
        patch.setEntity( new ByteArrayEntity(sparqlUpdate.getBytes()) );
        patch.setHeader("Content-Type", contentTypeSPARQLUpdate);
        return patch;
    }
689000
public static DoublesSketch wrap(final Memory srcMem) {
    if (checkIsCompactMemory(srcMem)) {
      return DirectCompactDoublesSketch.wrapInstance(srcMem);
    }
    return DirectUpdateDoublesSketchR.wrapInstance(srcMem);
  }