FreePastry/docs/javadoc/rice/p2p/util/MathUtils.html
ChronosX88 aaa73fe8b3 Pew
2019-05-13 16:45:05 +04:00

757 lines
26 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--NewPage-->
<HTML>
<HEAD>
<!-- Generated by javadoc (build 1.6.0_07) on Fri Mar 13 20:01:31 CET 2009 -->
<TITLE>
MathUtils (Rice Pastry - API Specifications)
</TITLE>
<META NAME="date" CONTENT="2009-03-13">
<LINK REL ="stylesheet" TYPE="text/css" HREF="../../../stylesheet.css" TITLE="Style">
<SCRIPT type="text/javascript">
function windowTitle()
{
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="MathUtils (Rice Pastry - API Specifications)";
}
}
</SCRIPT>
<NOSCRIPT>
</NOSCRIPT>
</HEAD>
<BODY BGCOLOR="white" onload="windowTitle();">
<HR>
<!-- ========= START OF TOP NAVBAR ======= -->
<A NAME="navbar_top"><!-- --></A>
<A HREF="#skip-navbar_top" title="Skip navigation links"></A>
<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
<TR>
<TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
<A NAME="navbar_top_firstrow"><!-- --></A>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
<TR ALIGN="center" VALIGN="top">
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/MathUtils.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
</TR>
</TABLE>
</TD>
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
Rice Pastry API</EM>
</TD>
</TR>
<TR>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
&nbsp;<A HREF="../../../rice/p2p/util/ImmutableSortedMap.html" title="class in rice.p2p.util"><B>PREV CLASS</B></A>&nbsp;
&nbsp;<A HREF="../../../rice/p2p/util/MCAdapter.html" title="class in rice.p2p.util"><B>NEXT CLASS</B></A></FONT></TD>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
<A HREF="../../../index.html?rice/p2p/util/MathUtils.html" target="_top"><B>FRAMES</B></A> &nbsp;
&nbsp;<A HREF="MathUtils.html" target="_top"><B>NO FRAMES</B></A> &nbsp;
&nbsp;<SCRIPT type="text/javascript">
<!--
if(window==top) {
document.writeln('<A HREF="../../../allclasses-noframe.html"><B>All Classes</B></A>');
}
//-->
</SCRIPT>
<NOSCRIPT>
<A HREF="../../../allclasses-noframe.html"><B>All Classes</B></A>
</NOSCRIPT>
</FONT></TD>
</TR>
<TR>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;<A HREF="#field_summary">FIELD</A>&nbsp;|&nbsp;CONSTR&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
DETAIL:&nbsp;<A HREF="#field_detail">FIELD</A>&nbsp;|&nbsp;CONSTR&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
</TR>
</TABLE>
<A NAME="skip-navbar_top"></A>
<!-- ========= END OF TOP NAVBAR ========= -->
<HR>
<!-- ======== START OF CLASS DATA ======== -->
<H2>
<FONT SIZE="-1">
rice.p2p.util</FONT>
<BR>
Class MathUtils</H2>
<PRE>
java.lang.Object
<IMG SRC="../../../resources/inherit.gif" ALT="extended by "><B>rice.p2p.util.MathUtils</B>
</PRE>
<HR>
<DL>
<DT><PRE>public class <B>MathUtils</B><DT>extends java.lang.Object</DL>
</PRE>
<P>
This class contains a large number of static methods for performing
math operations.
<P>
<P>
<DL>
<DT><B>Version:</B></DT>
<DD>$Id: MathUtils.java 4549 2008-10-16 18:21:19Z jeffh $</DD>
<DT><B>Author:</B></DT>
<DD>amislove</DD>
</DL>
<HR>
<P>
<!-- =========== FIELD SUMMARY =========== -->
<A NAME="field_summary"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
<B>Field Summary</B></FONT></TH>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;char[]</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../rice/p2p/util/MathUtils.html#HEX_ARRAY">HEX_ARRAY</A></B></CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The array used for conversion to hexadecimal</TD>
</TR>
</TABLE>
&nbsp;
<!-- ========== METHOD SUMMARY =========== -->
<A NAME="method_summary"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
<B>Method Summary</B></FONT></TH>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;int</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../rice/p2p/util/MathUtils.html#byteArrayToInt(byte[])">byteArrayToInt</A></B>(byte[]&nbsp;input)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Utility method for converting a byte[] into a int</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;int</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../rice/p2p/util/MathUtils.html#byteArrayToInt(byte[], int)">byteArrayToInt</A></B>(byte[]&nbsp;input,
int&nbsp;offset)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;long</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../rice/p2p/util/MathUtils.html#byteArrayToLong(byte[])">byteArrayToLong</A></B>(byte[]&nbsp;input)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Utility method for converting a byte[] into a long</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;long</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../rice/p2p/util/MathUtils.html#byteArrayToLong(byte[], int)">byteArrayToLong</A></B>(byte[]&nbsp;input,
int&nbsp;offset)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;short</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../rice/p2p/util/MathUtils.html#byteArrayToShort(byte[])">byteArrayToShort</A></B>(byte[]&nbsp;input)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;short</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../rice/p2p/util/MathUtils.html#byteArrayToShort(byte[], int)">byteArrayToShort</A></B>(byte[]&nbsp;input,
int&nbsp;offset)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;byte[]</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../rice/p2p/util/MathUtils.html#fromBase64(java.lang.String)">fromBase64</A></B>(java.lang.String&nbsp;text)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Utility method which converts a base64 string to a byte[]</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;byte[]</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../rice/p2p/util/MathUtils.html#fromHex(java.lang.String)">fromHex</A></B>(java.lang.String&nbsp;text)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Utility method which converts a hex string to a byte[]</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>protected static&nbsp;byte</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../rice/p2p/util/MathUtils.html#getByte(char)">getByte</A></B>(char&nbsp;c)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Utility method for converting a char to a byte</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;byte[]</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../rice/p2p/util/MathUtils.html#intToByteArray(int)">intToByteArray</A></B>(int&nbsp;input)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Utility method for converting a int into a byte[]</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../rice/p2p/util/MathUtils.html#intToByteArray(int, byte[], int)">intToByteArray</A></B>(int&nbsp;input,
byte[]&nbsp;output,
int&nbsp;offset)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Utility method for converting a int into a byte[]</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;byte</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../rice/p2p/util/MathUtils.html#intToUByte(int)">intToUByte</A></B>(int&nbsp;i)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;byte[]</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../rice/p2p/util/MathUtils.html#longToByteArray(long)">longToByteArray</A></B>(long&nbsp;input)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Utility method for converting a long into a byte[]</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../rice/p2p/util/MathUtils.html#longToByteArray(long, byte[], int)">longToByteArray</A></B>(long&nbsp;input,
byte[]&nbsp;output,
int&nbsp;offset)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Utility method for converting a long into a byte[]</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;int</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../rice/p2p/util/MathUtils.html#mod(int, int)">mod</A></B>(int&nbsp;a,
int&nbsp;b)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Utility which does *proper* modding, where the result is guaranteed to be
positive.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;byte[]</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../rice/p2p/util/MathUtils.html#randomBytes(int, rice.environment.random.RandomSource)">randomBytes</A></B>(int&nbsp;len,
<A HREF="../../../rice/environment/random/RandomSource.html" title="interface in rice.environment.random">RandomSource</A>&nbsp;random)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Method which returns a specified number of random bytes</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;int</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../rice/p2p/util/MathUtils.html#randomInt(rice.environment.random.RandomSource)">randomInt</A></B>(<A HREF="../../../rice/environment/random/RandomSource.html" title="interface in rice.environment.random">RandomSource</A>&nbsp;random)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Method which returns a random int</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;int</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../rice/p2p/util/MathUtils.html#simpleHash(byte[])">simpleHash</A></B>(byte[]&nbsp;b)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;A simple and fast hash function for hashing an arbitrary length
byte array into an int.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;java.lang.String</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../rice/p2p/util/MathUtils.html#toBase64(byte[])">toBase64</A></B>(byte[]&nbsp;text)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Utility method which converts a byte[] to a base64 string of characters, in lower case</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;java.lang.String</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../rice/p2p/util/MathUtils.html#toHex(byte[])">toHex</A></B>(byte[]&nbsp;text)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Utility method which converts a byte[] to a hexadecimal string of characters, in lower case</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;int</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../rice/p2p/util/MathUtils.html#uByteToInt(byte)">uByteToInt</A></B>(byte&nbsp;b)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;int</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../rice/p2p/util/MathUtils.html#uShortToInt(short)">uShortToInt</A></B>(short&nbsp;b)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;byte[]</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../rice/p2p/util/MathUtils.html#xor(byte[], byte[])">xor</A></B>(byte[]&nbsp;a,
byte[]&nbsp;b)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Utility method which xors two given byte arrays, of equal length, and returns the results</TD>
</TR>
</TABLE>
&nbsp;<A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
<TH ALIGN="left"><B>Methods inherited from class java.lang.Object</B></TH>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD><CODE>clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</CODE></TD>
</TR>
</TABLE>
&nbsp;
<P>
<!-- ============ FIELD DETAIL =========== -->
<A NAME="field_detail"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
<B>Field Detail</B></FONT></TH>
</TR>
</TABLE>
<A NAME="HEX_ARRAY"><!-- --></A><H3>
HEX_ARRAY</H3>
<PRE>
public static final char[] <B>HEX_ARRAY</B></PRE>
<DL>
<DD>The array used for conversion to hexadecimal
<P>
<DL>
</DL>
</DL>
<!-- ============ METHOD DETAIL ========== -->
<A NAME="method_detail"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
<B>Method Detail</B></FONT></TH>
</TR>
</TABLE>
<A NAME="mod(int, int)"><!-- --></A><H3>
mod</H3>
<PRE>
public static int <B>mod</B>(int&nbsp;a,
int&nbsp;b)</PRE>
<DL>
<DD>Utility which does *proper* modding, where the result is guaranteed to be
positive.
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>a</CODE> - The modee<DD><CODE>b</CODE> - The value to mod by
<DT><B>Returns:</B><DD>The result</DL>
</DD>
</DL>
<HR>
<A NAME="xor(byte[], byte[])"><!-- --></A><H3>
xor</H3>
<PRE>
public static byte[] <B>xor</B>(byte[]&nbsp;a,
byte[]&nbsp;b)</PRE>
<DL>
<DD>Utility method which xors two given byte arrays, of equal length, and returns the results
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>a</CODE> - The first array<DD><CODE>b</CODE> - The second array
<DT><B>Returns:</B><DD>A new byte array, xored</DL>
</DD>
</DL>
<HR>
<A NAME="randomBytes(int, rice.environment.random.RandomSource)"><!-- --></A><H3>
randomBytes</H3>
<PRE>
public static byte[] <B>randomBytes</B>(int&nbsp;len,
<A HREF="../../../rice/environment/random/RandomSource.html" title="interface in rice.environment.random">RandomSource</A>&nbsp;random)</PRE>
<DL>
<DD>Method which returns a specified number of random bytes
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>len</CODE> - The number of random bytes to generate</DL>
</DD>
</DL>
<HR>
<A NAME="randomInt(rice.environment.random.RandomSource)"><!-- --></A><H3>
randomInt</H3>
<PRE>
public static int <B>randomInt</B>(<A HREF="../../../rice/environment/random/RandomSource.html" title="interface in rice.environment.random">RandomSource</A>&nbsp;random)</PRE>
<DL>
<DD>Method which returns a random int
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>len</CODE> - The number of random bytes to generate</DL>
</DD>
</DL>
<HR>
<A NAME="toHex(byte[])"><!-- --></A><H3>
toHex</H3>
<PRE>
public static java.lang.String <B>toHex</B>(byte[]&nbsp;text)</PRE>
<DL>
<DD>Utility method which converts a byte[] to a hexadecimal string of characters, in lower case
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>text</CODE> - The array to convert
<DT><B>Returns:</B><DD>A string representation</DL>
</DD>
</DL>
<HR>
<A NAME="fromHex(java.lang.String)"><!-- --></A><H3>
fromHex</H3>
<PRE>
public static byte[] <B>fromHex</B>(java.lang.String&nbsp;text)</PRE>
<DL>
<DD>Utility method which converts a hex string to a byte[]
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>text</CODE> - The text to convert
<DT><B>Returns:</B><DD>The bytes</DL>
</DD>
</DL>
<HR>
<A NAME="toBase64(byte[])"><!-- --></A><H3>
toBase64</H3>
<PRE>
public static java.lang.String <B>toBase64</B>(byte[]&nbsp;text)</PRE>
<DL>
<DD>Utility method which converts a byte[] to a base64 string of characters, in lower case
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>text</CODE> - The array to convert
<DT><B>Returns:</B><DD>A string representation</DL>
</DD>
</DL>
<HR>
<A NAME="fromBase64(java.lang.String)"><!-- --></A><H3>
fromBase64</H3>
<PRE>
public static byte[] <B>fromBase64</B>(java.lang.String&nbsp;text)</PRE>
<DL>
<DD>Utility method which converts a base64 string to a byte[]
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>text</CODE> - The text to convert
<DT><B>Returns:</B><DD>The bytes</DL>
</DD>
</DL>
<HR>
<A NAME="simpleHash(byte[])"><!-- --></A><H3>
simpleHash</H3>
<PRE>
public static int <B>simpleHash</B>(byte[]&nbsp;b)</PRE>
<DL>
<DD>A simple and fast hash function for hashing an arbitrary length
byte array into an int. Not for crypto. Not to be trusted.
From Wikipedia: http://en.wikipedia.org/wiki/Hash_table
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>b</CODE> -
<DT><B>Returns:</B><DD>A hash of b</DL>
</DD>
</DL>
<HR>
<A NAME="getByte(char)"><!-- --></A><H3>
getByte</H3>
<PRE>
protected static byte <B>getByte</B>(char&nbsp;c)</PRE>
<DL>
<DD>Utility method for converting a char to a byte
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>c</CODE> - The char
<DT><B>Returns:</B><DD>The byte</DL>
</DD>
</DL>
<HR>
<A NAME="intToByteArray(int)"><!-- --></A><H3>
intToByteArray</H3>
<PRE>
public static byte[] <B>intToByteArray</B>(int&nbsp;input)</PRE>
<DL>
<DD>Utility method for converting a int into a byte[]
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>input</CODE> - The log to convert
<DT><B>Returns:</B><DD>a byte[] representation</DL>
</DD>
</DL>
<HR>
<A NAME="intToByteArray(int, byte[], int)"><!-- --></A><H3>
intToByteArray</H3>
<PRE>
public static void <B>intToByteArray</B>(int&nbsp;input,
byte[]&nbsp;output,
int&nbsp;offset)</PRE>
<DL>
<DD>Utility method for converting a int into a byte[]
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>input</CODE> - The log to convert</DL>
</DD>
</DL>
<HR>
<A NAME="byteArrayToInt(byte[])"><!-- --></A><H3>
byteArrayToInt</H3>
<PRE>
public static int <B>byteArrayToInt</B>(byte[]&nbsp;input)</PRE>
<DL>
<DD>Utility method for converting a byte[] into a int
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>input</CODE> - The byte[] to convert
<DT><B>Returns:</B><DD>a int representation</DL>
</DD>
</DL>
<HR>
<A NAME="byteArrayToInt(byte[], int)"><!-- --></A><H3>
byteArrayToInt</H3>
<PRE>
public static int <B>byteArrayToInt</B>(byte[]&nbsp;input,
int&nbsp;offset)</PRE>
<DL>
<DD><DL>
</DL>
</DD>
</DL>
<HR>
<A NAME="byteArrayToShort(byte[])"><!-- --></A><H3>
byteArrayToShort</H3>
<PRE>
public static short <B>byteArrayToShort</B>(byte[]&nbsp;input)</PRE>
<DL>
<DD><DL>
</DL>
</DD>
</DL>
<HR>
<A NAME="byteArrayToShort(byte[], int)"><!-- --></A><H3>
byteArrayToShort</H3>
<PRE>
public static short <B>byteArrayToShort</B>(byte[]&nbsp;input,
int&nbsp;offset)</PRE>
<DL>
<DD><DL>
</DL>
</DD>
</DL>
<HR>
<A NAME="longToByteArray(long)"><!-- --></A><H3>
longToByteArray</H3>
<PRE>
public static byte[] <B>longToByteArray</B>(long&nbsp;input)</PRE>
<DL>
<DD>Utility method for converting a long into a byte[]
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>input</CODE> - The log to convert
<DT><B>Returns:</B><DD>a byte[] representation</DL>
</DD>
</DL>
<HR>
<A NAME="longToByteArray(long, byte[], int)"><!-- --></A><H3>
longToByteArray</H3>
<PRE>
public static void <B>longToByteArray</B>(long&nbsp;input,
byte[]&nbsp;output,
int&nbsp;offset)</PRE>
<DL>
<DD>Utility method for converting a long into a byte[]
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>input</CODE> - The log to convert</DL>
</DD>
</DL>
<HR>
<A NAME="byteArrayToLong(byte[])"><!-- --></A><H3>
byteArrayToLong</H3>
<PRE>
public static long <B>byteArrayToLong</B>(byte[]&nbsp;input)</PRE>
<DL>
<DD>Utility method for converting a byte[] into a long
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>input</CODE> - The byte[] to convert
<DT><B>Returns:</B><DD>a long representation</DL>
</DD>
</DL>
<HR>
<A NAME="byteArrayToLong(byte[], int)"><!-- --></A><H3>
byteArrayToLong</H3>
<PRE>
public static long <B>byteArrayToLong</B>(byte[]&nbsp;input,
int&nbsp;offset)</PRE>
<DL>
<DD><DL>
</DL>
</DD>
</DL>
<HR>
<A NAME="uByteToInt(byte)"><!-- --></A><H3>
uByteToInt</H3>
<PRE>
public static int <B>uByteToInt</B>(byte&nbsp;b)</PRE>
<DL>
<DD><DL>
</DL>
</DD>
</DL>
<HR>
<A NAME="uShortToInt(short)"><!-- --></A><H3>
uShortToInt</H3>
<PRE>
public static int <B>uShortToInt</B>(short&nbsp;b)</PRE>
<DL>
<DD><DL>
</DL>
</DD>
</DL>
<HR>
<A NAME="intToUByte(int)"><!-- --></A><H3>
intToUByte</H3>
<PRE>
public static byte <B>intToUByte</B>(int&nbsp;i)</PRE>
<DL>
<DD><DL>
</DL>
</DD>
</DL>
<!-- ========= END OF CLASS DATA ========= -->
<HR>
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<A NAME="navbar_bottom"><!-- --></A>
<A HREF="#skip-navbar_bottom" title="Skip navigation links"></A>
<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
<TR>
<TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
<A NAME="navbar_bottom_firstrow"><!-- --></A>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
<TR ALIGN="center" VALIGN="top">
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/MathUtils.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
</TR>
</TABLE>
</TD>
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
Rice Pastry API</EM>
</TD>
</TR>
<TR>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
&nbsp;<A HREF="../../../rice/p2p/util/ImmutableSortedMap.html" title="class in rice.p2p.util"><B>PREV CLASS</B></A>&nbsp;
&nbsp;<A HREF="../../../rice/p2p/util/MCAdapter.html" title="class in rice.p2p.util"><B>NEXT CLASS</B></A></FONT></TD>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
<A HREF="../../../index.html?rice/p2p/util/MathUtils.html" target="_top"><B>FRAMES</B></A> &nbsp;
&nbsp;<A HREF="MathUtils.html" target="_top"><B>NO FRAMES</B></A> &nbsp;
&nbsp;<SCRIPT type="text/javascript">
<!--
if(window==top) {
document.writeln('<A HREF="../../../allclasses-noframe.html"><B>All Classes</B></A>');
}
//-->
</SCRIPT>
<NOSCRIPT>
<A HREF="../../../allclasses-noframe.html"><B>All Classes</B></A>
</NOSCRIPT>
</FONT></TD>
</TR>
<TR>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;<A HREF="#field_summary">FIELD</A>&nbsp;|&nbsp;CONSTR&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
DETAIL:&nbsp;<A HREF="#field_detail">FIELD</A>&nbsp;|&nbsp;CONSTR&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
</TR>
</TABLE>
<A NAME="skip-navbar_bottom"></A>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
<HR>
<i>Copyright &#169; 2001-2005 - Rice Pastry.</i>
</BODY>
</HTML>