📄 basics.java
字号:
package shared;
import java.lang.*;
import java.io.*;
/** Every file uses the members of the basics class. Here we define some constants, an
* initialization function and termination function. Note that since
* initialization order of static instances is not defined within different
* files, it is important that all initialization be done here, or at least
* that any other initialization will not depend on anything initialized here.
* This is especially a problem with constructors that call fatal_error and
* output to err, since err may not be initialized at that stage. Note the
* dependency between LONG_MAX and MAX_LONG_LEN.
*
* @author James Louis 8/16/2001 Ported to Java.
* @author Eric Eros 5/16/97 Created MLC class
* @author Ronny Kohavi 7/13/93 Initial revision (.c)
* @author Ronny Kohavi 8/26/93 Initial revision (.h)
*/
public class Basics {
//Compilation directives - JAL
/** TRUE if DBG sections of code should be executed, FALSE otherwise. Default is FALSE**/
public static boolean DBG = false;
/** TRUE if DBGSLOW sections of code should be executed, FALSE otherwise. Default is FALSE**/
public static boolean DBGSLOW = false;
/** The probability interval value used for calculating confidence.
*/
public static double CONFIDENCE_INTERVAL_PROBABILITY;
// MLC++ - Machine Learning Library in -*- C++ -*-
// See Descrip.txt for terms and conditions relating to use and distribution.
// This is an include file. For a full description of the class and
// functions, see the file "basicCore.c".
/** Default value for opening protections.
*/
public static int defaultOpenProt;
/** The prefix character for displaying error strings.
*/
public static char ERROR_PREFIX;
/** The character used to display when a line is being wrapped.
*/
public static char WRAP_INDENT;
/** Bad exit status for program.
*/
public static int BAD_STATUS;
/** Value used for error catching.
*/
public static String fatal_expected;
/** TRUE if mineset is being used, FALSE otherwise.
*/
public static boolean mineset; // for those messages specific to SGI's MineSet.
//obs public static char *minesetVersionStr;
/** The version of mineset being used.
*/
public static String minesetVersionStr;
//obs public static char *err_text;
/** Standard error text.
*/
public static String err_text;
//obs public static MLCOStream err;
/** Writer for output of error information.
*/
public static Writer err;
// note that MString.c assumes that Real is typedef'd to a double.
/** Maximum value for real numbers.
*/
public static double REAL_MAX;
/** Minimum number for real numbers.
*/
public static double REAL_MIN;
/** Maximum number for stored real numbers.
*/
public static float STORED_REAL_MAX;
/** Minimum number for stored real numbers.
*/
public static float STORED_REAL_MIN;
// For cases where a variable's value may be used as a flag to indicate
// it has not yet been set. These are extreme negative values.
// See basicCore.c
/** Number that designates undefined variance values.
*/
public static double UNDEFINED_VARIANCE;
/** Number that represents undefined real values.
*/
public static double UNDEFINED_REAL;
/** Number that represents undefined integer values.
*/
public static int UNDEFINED_INT;
// Default wrap width for an MStream, this guarantees that it is off initially
/** Number of characters allowed before a line is word wrapped.
*/
public static int DEFAULT_WRAP_WIDTH;
// Default wrap prefix for an MStream -3 spaces
//obs extern const char* DEFAULT_WRAP_PREFIX;
/** Prefix added to word wrapped lines.
*/
public static String DEFAULT_WRAP_PREFIX;
/*
// These are defined here because of a Bug in CFront that declared
// INT_MIN wrong (without (int)). What happens is that 2147483648
// does not fit in int, so it is made unsigned, then unary minus subtracts
// from max unsigned int to get the same number.
#ifdef CFRONT
#define SHORT_MAX 32767
#define LONG_MAX 2147483647
#define INT_MAX LONG_MAX
// defining LONG_MIN as -2147483648 does not work because the minus is
// a unary operator and the number causes it to be unsigned. We can
// cast to (long), but ObjectCenter gives a warning... This method
// is adapted from GNU limits.h
#define SHORT_MIN (-SHORT_MAX-1)
#define LONG_MIN (-LONG_MAX-1)
#define INT_MIN LONG_MIN
// MAX_LONG_LEN is used to define array dimensions so it cannot be
// extern const int.
// LONG_MAX is +2147483647 which is 10 digits +1 for sign.
// Note that this is an upper bound and MAX_LONG can be lower.
#define MAX_LONG_LEN 11
// Similar to LONG_MAX, 5 digits +1 for sign.
#define MAX_SHORT_LEN 6
#define UCHAR_MAX 255 // max value of an "unsigned char"
// Just use standard "limits.h" if we're not using CFRONT.
// We still need to set some of the symbols
#else
#include <limits.h>
#define SHORT_MAX 32767
#define SHORT_MIN (-SHORT_MAX-1)
#define MAX_LONG_LEN 11
#define MAX_SHORT_LEN 6
#endif
// In the following, DBL_DIG and FLT_DIG are defined in limits.h
// This is needed to set the precision of the stream when doing Real I/O
// This value is trunc((DSIGNIF - 1) / log2(10)),
// or trunc((FSIGNIF - 1) / log2(10)), where DSIGNIF is the
// number of significant bits for a double (defined in values.h),
// FSIGNIF is likewise defined for a float, and 1 is subtracted for
// the sign bit.
public static int REAL_MANTISSA_LEN = DBL_DIG; // 15
public static int STORED_REAL_MANTISSA_LEN = FLT_DIG; // 6
public static int MAX_ECVT_DIGITS = DBL_DIG+2; // 17
public static int MAX_ECVT_WIDTH = 84; // from man page for ecvt_r
*/
// Note: Should the size of Real and/or StoredReal change, the above
// numbers must change correspondingly. Also, REAL_EPSILON and
// STORED_REAL_EPSILON (in basicCore.c) must change.
// Because Reals can be displayed with full digits,
// MAX_REAL_LEN is set to a large number
// MAX_REAL_DIGITS specifies the maximum number of digits which may
// appear before the decimal point in a Real.
/** Maximum number of digits for real numbers.
*/
public static int MAX_REAL_DIGITS = 800;
/** Maximum length for real number display.
*/
public static int MAX_REAL_LEN = 2048;
/** Maximum length for stored real number display.
*/
public static int MAX_STORED_REAL_LEN = 2048;
/** MAX_WIDTH is the maximum width allowed for real output.
*/
public static int MAX_WIDTH = 2048;
/*
#ifndef _basic_h
#define _basic_h 1
#include <machine.h>
char is_compiled_fast(); // returns TRUE if library compiled in fast mode
#include <stdlib.h>
#include <math.h>
// There's sometimes a need to give a reference to something that
// is invalid. the SGI compiler warns about NULL ref, so this
// avoids the warning and is just as bad, i.e., an access will
// cause program to abort.
#define NULL_REF 1
// make sure nobody has defined Bool via #define. Xlib.h does this.
#ifdef Bool
#error Bool is already defined. Please undefine before including basics.h
#endif
// knock out any alternate TRUE or FALSE if defined
#ifdef TRUE
#undef TRUE
#endif
#ifdef FALSE
#undef FALSE
#endif
#ifdef _BOOL
typedef bool Bool; // After George Boole
# define TRUE true
# define FALSE false
#else
typedef char Bool;
# define TRUE Bool(!0)
# define FALSE Bool(0)
#endif
#ifndef FAST
#define DBG(stmts) if (GlobalOptions::debugLevel >= 1) {stmts;} else
#else
#define DBG(stmts)
#endif
#ifdef TEMPL_MAIN
#define TEMPL_GENERATOR(name) int main()
#else
#define TEMPL_GENERATOR(name) int name()
#endif
// DBGSLOW() should only be used for especially expensive code.
#ifndef FAST
#define DBGSLOW(stmts) if (GlobalOptions::debugLevel >= 2) {stmts;} else
#else
#define DBGSLOW(stmts)
#endif
// DBG_DECLARE() is intended for use in class or function declarations,
// where "if" statements are not allowed.
// Note that when using this macro, the semicolon must be INSIDE,
// since empty declarations are not allowed (r9.2)
#ifndef FAST
#define DBG_DECLARE(stmts) stmts
#else
#define DBG_DECLARE(stmts)
#endif
typedef double Real;
typedef float StoredReal; // for arrays etc.
// To prevent accidental copy construction, most copy constructors
// take a second "dummy" argument. Initially this dummy argument was
// forced to be an integer and that integer was checked to be 0,
// The new standard is that it would be much simpler to have the dummy
// argument be an actual enumerated type.
// Example usage:
// Foo.h: Foo(const Foo& foo, CtorDummy);
// Client.h: Foo foo2(foo1, ctorDummy);
enum CtorDummy {ctorDummy=0};
// Also, there is an enumerated type for dummy arguments.
enum ArgDummy {argDummy=0};
// Declarations for the parallel execution using pthread library. Currently
// only entropy discretizors are parallelized. Do not define this constant if
// you do not want to use pthreads
// #define PTHREADS
#ifdef PTHREADS
#include <malloc.h>
#include <unistd.h>
#include <pthread.h>
#include <sys/shm.h>
#include <sys/types.h>
#include <sys/resource.h>
#include <sys/prctl.h>
#define PTHR_DECL(stmts) stmts
#else
#define PTHR_DECL(stmts)
#endif // PTHREADS
#include <time.h>
#include <MString.h>
#include <GlobalOptions.h>
// Due to archaic 8+3 PC naming conventions, strstream.h
// is sometimes called strstrea.h
#ifdef PC_MSVC
#include <strstrea.h>
#else
#include <strstream.h>
#endif
#ifdef __GNUC__
typedef timespec timespec_t;
#endif
/* G++ and other smart and proper compilers define null as a variable, to
* escape type sensitive situations. However, this breaks operator overloading
* for comparason operators that require NULL to be 0, (traditional C++)
*
#undef NULL
#define NULL 0
#include <error.h>
// MLCInit class to force consistent initialization order
class MLCInit {
NO_DEFAULT_OPS(MLCInit);
public:
// Public data
static int count;
// Methods
MLCInit() { if(count++ == 0) startup(); }
~MLCInit() { if(--count == 0) shutdown(); }
void startup();
void shutdown();
};
// static instance of MLCInit: used for force initialization order.
// note that this instance is DEFINED here in the header file; this
// forces its definition to occur BEFORE all other definitions in
// each file which includes basics.h, and thus before all other
// static initialization.
static MLCInit mlcInit;
// Enumerated type to declare constructors which indicate that a static
// instance should be initialized externally
enum UseExternalCtor { useExternalCtor = 1 };
// This macro causes a fatal_error if the given condition is FALSE.
// The behavior is similar to the C/C++ assert (see include/assert.h).
// The macro is executed as a DBG statement.
// These allow sharing the same message string across files to
// save space (also help with gp_overflow(5) errors.
extern const char *ASSERT_FAILURE_MSG;
extern const char *ASSERT_FILE_MSG;
extern const char *ASSERT_LINE_MSG;
// ASSERTs for debugging purposes should be in DBG().
#define ASSERT(stmt) \
((stmt)?((void)0): \
(void)(err << ASSERT_FAILURE_MSG << # stmt << \
ASSERT_FILE_MSG << __FILE__ << \
ASSERT_LINE_MSG << __LINE__ << fatal_error))
// Old version below caused compiler core dump on SGI and ConstCat
// (void)((stmt) || \
// ((err << "MLC++ internal error: assertion failed: " # stmt \
// ", file " << __FILE__ << ", line " << __LINE__ << fatal_error), 0))
#define ABORT_IF_REACHED \
err << "MLC++ internal error: unexpected condition in file " \
<< __FILE__ << ", line " << __LINE__ << fatal_error
#include <MLCStream.h>
extern MLCIStream Mcin;
extern MLCOStream Mcout;
extern MLCOStream Mcerr;
// DBG*(code) needs a trailing semicolon outside, i.e. DBG(x=3);
// The last statement inside does not need a semicolon. The semicolon
// outside allows proper indentation in Emacs C++ mode.
// and is also required inside IFs to generate an empty statement.
// The "else" is so DBG will work even if it is inside an if statement.
// (the else in the definition assures proper matching of the else
// in the code, and also makes use of the semicolon...):
//
// if (foo)
// DBG(bar);
// else
// kuku();
// This is the size of the buffer used for reading and writing files.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -