List of usage examples for java.lang Long SIZE
int SIZE
To view the source code for java.lang Long SIZE.
Click Source Link
From source file:Main.java
public static void main(String[] args) { System.out.println(Long.SIZE); }
From source file:it.unimi.di.big.mg4j.tool.URLMPHVirtualDocumentResolver.java
public static void main(final String[] arg) throws JSAPException, IOException { final SimpleJSAP jsap = new SimpleJSAP(URLMPHVirtualDocumentResolver.class.getName(), "Builds a URL document resolver from a sequence of URIs, extracted typically using ScanMetadata, using a suitable function. You can specify that the list is sorted, in which case it is possible to generate a resolver that occupies less space.", new Parameter[] { new Switch("sorted", 's', "sorted", "URIs are sorted: use a monotone minimal perfect hash function."), new Switch("iso", 'i', "iso", "Use ISO-8859-1 coding internally (i.e., just use the lower eight bits of each character)."), new FlaggedOption("bufferSize", JSAP.INTSIZE_PARSER, "64Ki", JSAP.NOT_REQUIRED, 'b', "buffer-size", "The size of the I/O buffer used to read terms."), new FlaggedOption("class", MG4JClassParser.getParser(), JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 'c', "class", "A class used to create the function from URIs to their ranks; defaults to it.unimi.dsi.sux4j.mph.MHWCFunction for non-sorted inputs, and to it.unimi.dsi.sux4j.mph.TwoStepsLcpMonotoneMinimalPerfectHashFunction for sorted inputs."), new FlaggedOption("width", JSAP.INTEGER_PARSER, Integer.toString(Long.SIZE), JSAP.NOT_REQUIRED, 'w', "width", "The width, in bits, of the signatures used to sign the function from URIs to their rank."), new FlaggedOption("termFile", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 'o', "offline", "Read terms from this file (without loading them into core memory) instead of standard input."), new FlaggedOption("uniqueUris", JSAP.INTSIZE_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 'U', "unique-uris", "Force URIs to be unique by adding random garbage at the end of duplicates; the argument is an upper bound for the number of URIs that will be read, and will be used to create a Bloom filter."), new UnflaggedOption("resolver", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.NOT_GREEDY, "The filename for the resolver.") }); JSAPResult jsapResult = jsap.parse(arg); if (jsap.messagePrinted()) return;//w w w . j a v a 2s . co m final int bufferSize = jsapResult.getInt("bufferSize"); final String resolverName = jsapResult.getString("resolver"); //final Class<?> tableClass = jsapResult.getClass( "class" ); final boolean iso = jsapResult.getBoolean("iso"); String termFile = jsapResult.getString("termFile"); BloomFilter<Void> filter = null; final boolean uniqueURIs = jsapResult.userSpecified("uniqueUris"); if (uniqueURIs) filter = BloomFilter.create(jsapResult.getInt("uniqueUris")); final Collection<? extends CharSequence> collection; if (termFile == null) { ArrayList<MutableString> termList = new ArrayList<MutableString>(); final ProgressLogger pl = new ProgressLogger(); pl.itemsName = "URIs"; final LineIterator termIterator = new LineIterator( new FastBufferedReader(new InputStreamReader(System.in, "UTF-8"), bufferSize), pl); pl.start("Reading URIs..."); MutableString uri; while (termIterator.hasNext()) { uri = termIterator.next(); if (uniqueURIs) makeUnique(filter, uri); termList.add(uri.copy()); } pl.done(); collection = termList; } else { if (uniqueURIs) { // Create temporary file with unique URIs final ProgressLogger pl = new ProgressLogger(); pl.itemsName = "URIs"; pl.start("Copying URIs..."); final LineIterator termIterator = new LineIterator( new FastBufferedReader(new InputStreamReader(new FileInputStream(termFile)), bufferSize), pl); File temp = File.createTempFile(URLMPHVirtualDocumentResolver.class.getName(), ".uniqueuris"); temp.deleteOnExit(); termFile = temp.toString(); final FastBufferedOutputStream outputStream = new FastBufferedOutputStream( new FileOutputStream(termFile), bufferSize); MutableString uri; while (termIterator.hasNext()) { uri = termIterator.next(); makeUnique(filter, uri); uri.writeUTF8(outputStream); outputStream.write('\n'); } pl.done(); outputStream.close(); } collection = new FileLinesCollection(termFile, "UTF-8"); } LOGGER.debug("Building function..."); final int width = jsapResult.getInt("width"); if (jsapResult.getBoolean("sorted")) BinIO.storeObject( new URLMPHVirtualDocumentResolver( new ShiftAddXorSignedStringMap(collection.iterator(), new TwoStepsLcpMonotoneMinimalPerfectHashFunction<CharSequence>(collection, iso ? TransformationStrategies.prefixFreeIso() : TransformationStrategies.prefixFreeUtf16()), width)), resolverName); else BinIO.storeObject( new URLMPHVirtualDocumentResolver(new ShiftAddXorSignedStringMap(collection.iterator(), new MWHCFunction<CharSequence>(collection, iso ? TransformationStrategies.iso() : TransformationStrategies.utf16()), width)), resolverName); LOGGER.debug(" done."); }
From source file:Main.java
/** * @param delta//from w ww . jav a2s . c om * @return */ private static int getNumBits(final long delta) { return Long.SIZE - Long.numberOfLeadingZeros(delta); }
From source file:Main.java
public static byte[] longToBytes(long x) { ByteBuffer buffer = ByteBuffer.allocate(Long.SIZE / 8); buffer.putLong(0, x);//w ww . jav a 2 s . c o m return buffer.array(); }
From source file:Main.java
/** * 7 => 00000111//from w ww .j a va 2 s .c o m * * @param src * @return */ public static String getBinaryString(long src) { String binaryString = Long.toBinaryString(src); String temp = ""; for (int i = 0; i < Long.SIZE - binaryString.length(); i++) { temp += "0"; } binaryString = temp + binaryString; return binaryString; }
From source file:Main.java
public static int getVNumSize(long i) { if (i >= -112 && i <= 127) { return 1; }// w ww. java 2s . com if (i < 0) { i ^= -1L; // take one's complement' } // find the number of bytes with non-leading zeros int dataBits = Long.SIZE - Long.numberOfLeadingZeros(i); // find the number of data bytes + length byte return (dataBits + 7) / 8 + 1; }
From source file:Main.java
/** * Takes the 8 bytes and converts them to an integer. * * @param buffer offset + 8 bytes containing the long * @param offset the index where the long start in the buffer * @return the long from the buffer.// www. j a v a 2 s. c o m */ public static long longFromBuffer(byte[] buffer, int offset) { long result = 0; for (int i = 0; i < Long.SIZE / Byte.SIZE; i++) { result <<= Byte.SIZE; result |= (buffer[offset + i] & 0xFF); } return result; }
From source file:Main.java
/** * Convert the given byte array to 'long' * //from ww w . ja v a 2 s .c om * @param b * An 8-byte array * @return long value of the array contents */ public static long convertByteArrayToLong(byte[] b) { int capacity = Long.SIZE / EIGHT; if (b.length > capacity) { return -1; } return ByteBuffer.wrap(b).getLong(); }
From source file:Main.java
/** * Convert the given long to an 8-byte array * /*from w w w . j a va 2 s. c o m*/ * @param l * A 'long' * * @return An 8-byte array in big endian (MSB) ordering */ public static byte[] convertLongToByteArrayBigEndian(long l) { return ByteBuffer.allocate(Long.SIZE / EIGHT).putLong(l).array(); }
From source file:Main.java
/** * @param byteArray//from w ww . ja v a 2 s . com * @return */ public static long byteArrayToUnsignedLong(byte[] byteArray) { int length; long value = 0; if (byteArray.length == Byte.SIZE / Byte.SIZE) { length = Byte.SIZE / Byte.SIZE; } else if (byteArray.length == Short.SIZE / Byte.SIZE) { length = Short.SIZE / Byte.SIZE; } else if (byteArray.length == Integer.SIZE / Byte.SIZE) { length = Integer.SIZE / Byte.SIZE; } else if (byteArray.length == Long.SIZE / Byte.SIZE) { length = Long.SIZE / Byte.SIZE; } else throw new IllegalArgumentException("Array length must match one of the following types:\n Byte==" + Byte.SIZE + ", Short==" + Short.SIZE + ", Integer==" + Integer.SIZE + ", Long==" + Long.SIZE); for (int i = 0; i < length; i++) { value |= ((0xffL & byteArray[i]) << (8 * (length - i - 1))); } return value; }