Package net.cscott.jutil
Class Util
java.lang.Object
net.cscott.jutil.Util
Miscellaneous static utility functions.
- Author:
- C. Scott Ananian <cananian@alumni.princeton.edu>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic final intffs(int v) Find first set (least significant bit).static final intffs(long v) Find first set (least significant bit).static final intfls(int v) Find last set (most significant bit).static final intfls(long v) Find last set (most significant bit).static final intgcd(int u, int v) Returns the greatest common divisor of a pair of numbers.static final longgcd(long u, long v) Returns the greatest common divisor of a pair of numbers.static final intlog2c(int v) Returns ceil(log2(n))static final intpopcount(int v) Deprecated.static final intpopcount(long v) Deprecated.UseLong.bitCount(long).static final StringrepeatString(String s, int n) Deprecated.UseString.repeat(int).static final intzerocount(int v) Deprecated.UseInteger.bitCount(~v).static final intzerocount(long v) Deprecated.UseLong.bitCount(~v).
-
Constructor Details
-
Util
public Util()
-
-
Method Details
-
repeatString
Deprecated.UseString.repeat(int).Repeat a given string a certain number of times.- Returns:
- a string consisting of
srepeatedntimes.
-
ffs
public static final int ffs(int v) Find first set (least significant bit).- Returns:
- the first bit set in the argument.
ffs(0)==0andffs(1)==1.
-
ffs
public static final int ffs(long v) Find first set (least significant bit).- Returns:
- the first bit set in the argument.
ffs(0)==0andffs(1)==1.
-
fls
public static final int fls(int v) Find last set (most significant bit).- Returns:
- the last bit set in the argument.
fls(0)==0andfls(1)==1.
-
fls
public static final int fls(long v) Find last set (most significant bit).- Returns:
- the last bit set in the argument.
fls(0)==0andfls(1)==1.
-
log2c
public static final int log2c(int v) Returns ceil(log2(n)) -
zerocount
Deprecated.UseInteger.bitCount(~v).Return the number of zeros in the binary representation of the value of the argument. -
zerocount
Deprecated.UseLong.bitCount(~v).Return the number of zeros in the binary representation of the value of the argument. -
popcount
Deprecated.Return the number of ones in the binary representation of the value of the argument. -
popcount
Deprecated.UseLong.bitCount(long).Return the number of ones in the binary representation of the value of the argument. -
gcd
public static final long gcd(long u, long v) Returns the greatest common divisor of a pair of numbers. -
gcd
public static final int gcd(int u, int v) Returns the greatest common divisor of a pair of numbers.
-
Integer.bitCount(int).