📄 fast.java
字号:
: ( x < 1L<<50 ? 49 /* 6 */ : 50 /* 6 */ ) ) : ( x < 1L<<53 ? ( x < 1L<<52 ? 51 /* 6 */ : 52 /* 6 */ ) : ( x < 1L<<54 ? 53 /* 6 */ : 54 /* 6 */ ) ) ) : ( x < 1L<<59 ? ( x < 1L<<57 ? ( x < 1L<<56 ? 55 /* 6 */ : 56 /* 6 */ ) : ( x < 1L<<58 ? 57 /* 6 */ : 58 /* 6 */ ) ) : ( x < 1L<<61 ? ( x < 1L<<60 ? 59 /* 6 */ : 60 /* 6 */ ) : ( x < 1L<<62 ? 61 /* 6 */ : 62 /* 6 */ ) ) ) ) ) ); } /** Computes the least significant bit of an integer. * * @param x an integer. * @return the least significant bit of the argument (-1 for 0). * @deprecated Moved to <code>dsiutils</code>. */ @Deprecated public static int leastSignificantBit( final int x ) { if ( x == 0 ) return -1; if ( ( x & 0xFF ) != 0 ) return BYTELSB[ x & 0xFF ]; if ( ( x & 0xFFFF ) != 0 ) return BYTELSB[ x >>> 8 & 0xFF ] + 8; if ( ( x & 0xFFFFFF ) != 0 ) return BYTELSB[ x >>> 16 & 0xFF ]+ 16; return BYTELSB[ x >>> 24 & 0xFF ] + 24; } /** Computes the least significant bit of a long integer. * * @param x a long integer. * @return the least significant bit of the argument (-1 for 0). * @deprecated Moved to <code>dsiutils</code>. */ @Deprecated public static int leastSignificantBit( final long x ) { if ( x == 0 ) return -1; if ( ( x & 0xFF ) != 0 ) return BYTELSB[ (int)( x & 0xFF ) ]; if ( ( x & 0xFFFF ) != 0 ) return BYTELSB[ (int)( x >>> 8 & 0xFF ) ] + 8; if ( ( x & 0xFFFFFF ) != 0 ) return BYTELSB[ (int)( x >>> 16 & 0xFF ) ] + 16; if ( ( x & 0xFFFFFFFFL ) != 0 ) return BYTELSB[ (int)( x >>> 24 & 0xFF ) ] + 24; if ( ( x & 0xFFFFFFFFFFL ) != 0 ) return BYTELSB[ (int)( x >>> 32 & 0xFF ) ] + 32; if ( ( x & 0xFFFFFFFFFFFFL ) != 0 ) return BYTELSB[ (int)( x >>> 40 & 0xFF ) ] + 40; if ( ( x & 0xFFFFFFFFFFFFFFL ) != 0 ) return BYTELSB[ (int)( x >>> 48 & 0xFF ) ] + 48; return BYTELSB[ (int)( x >>> 56 & 0xFF ) ] + 56; } /** Maps integers bijectively into natural numbers. * * <P>This method will map a negative integer <var>x</var> to -2<var>x</var>-1 and * a nonnegative integer <var>x</var> to 2<var>x</var>. It can be used to save * integers in the range [{@link Integer#MIN_VALUE}/2..{@link Integer#MAX_VALUE}/2] * (i.e., [-2<sup>30</sup>..2<sup>30</sup>-1]) * using the standard coding methods (which all work on natural numbers). Note * that no range checks are performed. * * <P>The inverse of the above map is computed by {@link #nat2int(int)}. * * @param x an integer. * @return the argument mapped into a natural number. * @see #nat2int(int) * @deprecated Moved to <code>dsiutils</code>. */ @Deprecated public static int int2nat( final int x ) { return x >= 0 ? x << 1 : -( ( x << 1 ) + 1 ); } /** Maps natural numbers bijectively into integers. * * <P>This method computes the inverse of {@link #int2nat(int)}. * * @param x a natural number. * @return the argument mapped into an integer. * @see #int2nat(int) * @deprecated Moved to <code>dsiutils</code>. */ @Deprecated public static int nat2int( final int x ) { return x % 2 == 0 ? x >> 1 : -( x >> 1 ) - 1; } /** Maps longs bijectively into long natural numbers. * * <P>This method will map a negative long <var>x</var> to -2<var>x</var>-1 and * a nonnegative long <var>x</var> to 2<var>x</var>. It can be used to save * longs in the range [{@link Long#MIN_VALUE}/2..{@link Long#MAX_VALUE}/2] * (i.e., [-2<sup>62</sup>..2<sup>62</sup>-1]) * using the standard coding methods (which all work on natural numbers). Note * that no range checks are performed. * * <P>The inverse of the above map is computed by {@link #nat2int(long)}. * * @param x a long. * @return the argument mapped into a long natural number. * @see #int2nat(int) * @deprecated Moved to <code>dsiutils</code>. */ @Deprecated public static long int2nat( final long x ) { return x >= 0 ? x << 1 : -( ( x << 1 ) + 1 ); } /** Maps long natural numbers bijectively into longs. * * <P>This method computes the inverse of {@link #int2nat(long)}. * * @param x a long natural number. * @return the argument mapped into a long. * @see #nat2int(int) * @deprecated Moved to <code>dsiutils</code>. */ @Deprecated public static long nat2int( final long x ) { return x % 2 == 0 ? x >> 1 : -( x >> 1 ) - 1; } /** A reasonable format for real numbers. */ private static final java.text.NumberFormat FORMAT_DOUBLE = new java.text.DecimalFormat( "#,##0.00" ); /** Formats a number. * * <P>This method formats a double separating thousands and printing just two fractional digits. * @param d a number. * @return a string containing a pretty print of the number. * @deprecated Moved to <code>dsiutils</code>. */ @Deprecated public static String format( final double d ) { final StringBuffer s = new StringBuffer(); return FORMAT_DOUBLE.format( d, s, new java.text.FieldPosition( 0 ) ).toString(); } /** A reasonable format for integers. */ private static final java.text.NumberFormat FORMAT_LONG = new java.text.DecimalFormat( "#,###" ); /** Formats a number. * * <P>This method formats a long separating thousands. * @param l a number. * @return a string containing a pretty print of the number. * @deprecated Moved to <code>dsiutils</code>. */ @Deprecated public static String format( final long l ) { final StringBuffer s = new StringBuffer(); return FORMAT_LONG.format( l, s, new java.text.FieldPosition( 0 ) ).toString(); } /** Formats a size. * * <P>This method formats a long using suitable unit multipliers (e.g., <samp>K</samp>, <samp>M</samp>, <samp>G</samp>, and <samp>T</samp>) * and printing just two fractional digits. * @param l a number, representing a size (e.g., memory). * @return a string containing a pretty print of the number using unit multipliers. * @deprecated Moved to <code>dsiutils</code>. */ @Deprecated public static String formatSize( final long l ) { if ( l >= 1000000000000L ) return format( l / 1000000000000.0 ) + "T"; if ( l >= 1000000000L ) return format( l / 1000000000.0 ) + "G"; if ( l >= 1000000L ) return format( l / 1000000.0 ) + "M"; if ( l >= 1000L ) return format( l / 1000.0 ) + "K"; return Long.toString( l ); } /** Formats a binary size. * * <P>This method formats a long using suitable unit binary multipliers (e.g., <samp>Ki</samp>, <samp>Mi</samp>, <samp>Gi</samp>, and <samp>Ti</samp>) * and printing <em>no</em> fractional digits. The argument must be a power of 2. * @param l a number, representing a binary size (e.g., memory); must be a power of 2. * @return a string containing a pretty print of the number using binary unit multipliers. * @deprecated Moved to <code>dsiutils</code>. */ @Deprecated public static String formatBinarySize( final long l ) { if ( ( l & -l ) != l ) throw new IllegalArgumentException( "Not a power of 2: " + l ); if ( l >= ( 1L << 40 ) ) return format( l >> 40 ) + "Ti"; if ( l >= ( 1L << 30 ) ) return format( l >> 30 ) + "Gi"; if ( l >= ( 1L << 20 ) ) return format( l >> 20 ) + "Mi"; if ( l >= ( 1L << 10 ) ) return format( l >> 10 ) + "Ki"; return Long.toString( l ); } /** Precomputed least significant bits for bytes (-1 for 0 ). * @deprecated Moved to <code>dsiutils</code>. */ @Deprecated public static final int[] BYTELSB = { -1, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 7, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0 }; /** Precomputed most significant bits for bytes (-1 for 0 ). * @deprecated Moved to <code>dsiutils</code>. */ @Deprecated public static final int[] BYTEMSB = { -1, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7 }; /** Checks whether Log4J is properly configuring by searching for appenders in all loggers. * * @return whether Log4J is configured (or, at least, an educated guess). * @deprecated Moved to <code>dsiutils</code>. * */ @Deprecated public static boolean log4JIsConfigured() { if ( Logger.getRootLogger().getAllAppenders().hasMoreElements() ) return true; Enumeration<?> loggers = LogManager.getCurrentLoggers(); while ( loggers.hasMoreElements() ) { Logger logger = (Logger)loggers.nextElement(); if ( logger.getAllAppenders().hasMoreElements() ) return true; } return false; } /** Ensures that Log4J is configured, by invoking, if necessary, * {@link org.apache.log4j.BasicConfigurator#configure()}, and * setting the root logger level to {@link Level#INFO}. * @deprecated Moved to <code>dsiutils</code>. */ @Deprecated public static void ensureLog4JIsConfigured() { ensureLog4JIsConfigured( Level.INFO ); } /** Ensures that Log4J is configured, by invoking, if necessary, * {@link org.apache.log4j.BasicConfigurator#configure()}, and * setting the root logger level to <code>level</code>. * * @param level the required logging level. * @deprecated Moved to <code>dsiutils</code>. */ @Deprecated public static void ensureLog4JIsConfigured( final Level level ) { if ( ! log4JIsConfigured() ) { System.err.println( "WARNING: MG4J is autoconfiguring Log4J. You should configure Log4J properly instead." ); BasicConfigurator.configure(); LogManager.getRootLogger().setLevel( level ); } } /** Calls Log4J's {@link Logger#getLogger(java.lang.Class)} method and then {@link #ensureLog4JIsConfigured()}. * * @param klass a class that will be passed to {@link Logger#getLogger(java.lang.Class)}. * @return the logger returned by {@link Logger#getLogger(java.lang.Class)}. * @deprecated Moved to <code>dsiutils</code>. */ @Deprecated public static Logger getLogger( final Class<?> klass ) { Logger logger = Logger.getLogger( klass ); ensureLog4JIsConfigured(); return logger; } private final static Runtime RUNTIME = Runtime.getRuntime(); /** Returns true if less then 5% of the available memory is free. * * @return true if less then 5% of the available memory is free. * @deprecated Moved to <code>dsiutils</code>. */ @Deprecated public static boolean memoryIsLow() { return availableMemory() * 100 < RUNTIME.totalMemory() * 5; } /** Returns the amount of available memory (free memory plus never allocated memory). * * @return the amount of available memory, in bytes. * @deprecated Moved to <code>dsiutils</code>. */ @Deprecated public static long availableMemory() { return RUNTIME.freeMemory() + ( RUNTIME.maxMemory() - RUNTIME.totalMemory() ); } /** Returns the percentage of available memory (free memory plus never allocated memory). * * @return the percentage of available memory. * @deprecated Moved to <code>dsiutils</code>. */ @Deprecated public static int percAvailableMemory() { return (int)( ( Fast.availableMemory() * 100 ) / Runtime.getRuntime().maxMemory() ); } /** Tries to compact memory as much as possible by forcing garbage collection. * @deprecated Moved to <code>dsiutils</code>. */ @Deprecated public static void compactMemory() { try { @SuppressWarnings("unused") final byte[][] unused = new byte[ 128 ][]; for( int i = unused.length; i-- != 0; ) unused[ i ] = new byte[ 2000000000 ]; } catch ( OutOfMemoryError itsWhatWeWanted ) {} }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -