aa
com.cliffc.aa.type.Bits< B extends Bits< B >.Tree< B extends Bits< B > Class Template Reference
Inheritance diagram for com.cliffc.aa.type.Bits< B extends Bits< B >.Tree< B extends Bits< B >:
[legend]
Collaboration diagram for com.cliffc.aa.type.Bits< B extends Bits< B >.Tree< B extends Bits< B >:
[legend]

Public Member Functions

int[] get_kids (int par)
 
boolean is_parent (int idx)
 
int next_kid (int alias, int kid)
 
VBitSet plus_kids (Bits< B > bits)
 
String toString ()
 

Package Functions

void _plus_kids (VBitSet bs, int i)
 
void init0 ()
 
boolean is_parent (int par, int kid)
 
int parent (int kid)
 
int peek ()
 
void reset_to_init0 ()
 
int split (int par)
 

Package Attributes

int _cnt = 1
 
int[] _init
 
int[][] _kids = new int[2][]
 
int[] _pars = new int[2]
 

Private Member Functions

SB toString (SB sb, int i)
 

Detailed Description

Definition at line 402 of file Bits.java.

Member Function Documentation

◆ _plus_kids()

void com.cliffc.aa.type.Bits< B extends Bits< B >.Tree< B extends Bits< B >._plus_kids ( VBitSet  bs,
int  i 
)
package

Definition at line 490 of file Bits.java.

490  {
491  bs.set(i);
492  int nkids = i >= _kids.length || _kids[i]==null ? 0 : _kids[i][0];
493  for( int kid=1; kid<nkids; kid++ )
494  _plus_kids(bs,_kids[i][kid]);
495  }

References com.cliffc.aa.type.Bits< B extends Bits< B >.Tree< B extends Bits< B >._kids.

Referenced by com.cliffc.aa.type.Bits< B extends Bits< B >.Tree< B extends Bits< B >.plus_kids().

Here is the caller graph for this function:

◆ get_kids()

int [] com.cliffc.aa.type.Bits< B extends Bits< B >.Tree< B extends Bits< B >.get_kids ( int  par)

Definition at line 412 of file Bits.java.

412 { assert _kids[par][0]==3; return _kids[par]; }

References com.cliffc.aa.type.Bits< B extends Bits< B >.Tree< B extends Bits< B >._kids.

◆ init0()

void com.cliffc.aa.type.Bits< B extends Bits< B >.Tree< B extends Bits< B >.init0 ( )
package

Definition at line 469 of file Bits.java.

469  {
470  _init = new int[_kids.length];
471  for( int i=0; i<_kids.length; i++ )
472  _init[i] = _kids[i]==null ? 1 : _kids[i][0];
473  }

References com.cliffc.aa.type.Bits< B extends Bits< B >.Tree< B extends Bits< B >._init, and com.cliffc.aa.type.Bits< B extends Bits< B >.Tree< B extends Bits< B >._kids.

◆ is_parent() [1/2]

boolean com.cliffc.aa.type.Bits< B extends Bits< B >.Tree< B extends Bits< B >.is_parent ( int  idx)

Definition at line 410 of file Bits.java.

410 { return idx<_kids.length && _kids[idx]!=null &&_kids[idx][0]>1; }

References com.cliffc.aa.type.Bits< B extends Bits< B >.Tree< B extends Bits< B >._kids, and com.cliffc.aa.type.Bits< B extends Bits< B >.idx().

Referenced by com.cliffc.aa.type.Bits< B extends Bits< B >.Tree< B extends Bits< B >.next_kid(), and com.cliffc.aa.type.Bits< B extends Bits< B >.Tree< B extends Bits< B >.toString().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_parent() [2/2]

boolean com.cliffc.aa.type.Bits< B extends Bits< B >.Tree< B extends Bits< B >.is_parent ( int  par,
int  kid 
)
package

Definition at line 414 of file Bits.java.

414  {
415  for( ; par <= kid; kid = parent(kid) )
416  if( par==kid ) return true;
417  return false; // Kid will be a larger number
418  }

References com.cliffc.aa.type.Bits< B extends Bits< B >.Tree< B extends Bits< B >.parent().

Here is the call graph for this function:

◆ next_kid()

int com.cliffc.aa.type.Bits< B extends Bits< B >.Tree< B extends Bits< B >.next_kid ( int  alias,
int  kid 
)

Definition at line 500 of file Bits.java.

500  {
501  if( kid==0 ) return 0;
502  boolean is_par = is_parent(kid);
503  if( kid==alias && !is_par ) return 0; // Singleton bit
504  // Find kid in the alias-tree
505  if( is_par ) { // Go deeper
506  return _kids[kid][1]; // First child one layer deeper
507  } else { // Leaf, unwind & find sibling
508  while(kid!=alias) {
509  int par = _pars[kid]; // Parent
510  int[] kids = _kids[par]; // All the parents' children
511  for( int i=1; i<kids[0]-1; i++ )
512  if( kids[i]==kid )
513  return kids[i+1]; // Return sibling
514  kid=par; // Up-parent & go again
515  }
516  return 0; // Last child visited
517  }
518  }

References com.cliffc.aa.type.Bits< B extends Bits< B >.Tree< B extends Bits< B >._kids, com.cliffc.aa.type.Bits< B extends Bits< B >.Tree< B extends Bits< B >._pars, and com.cliffc.aa.type.Bits< B extends Bits< B >.Tree< B extends Bits< B >.is_parent().

Here is the call graph for this function:

◆ parent()

int com.cliffc.aa.type.Bits< B extends Bits< B >.Tree< B extends Bits< B >.parent ( int  kid)
package

Definition at line 409 of file Bits.java.

409 { return _pars[kid]; }

References com.cliffc.aa.type.Bits< B extends Bits< B >.Tree< B extends Bits< B >._pars.

Referenced by com.cliffc.aa.type.Bits< B extends Bits< B >.Tree< B extends Bits< B >.is_parent().

Here is the caller graph for this function:

◆ peek()

int com.cliffc.aa.type.Bits< B extends Bits< B >.Tree< B extends Bits< B >.peek ( )
package

Definition at line 480 of file Bits.java.

480 { return _kids[1][_kids[1][0]]; } // for testing

References com.cliffc.aa.type.Bits< B extends Bits< B >.Tree< B extends Bits< B >._kids.

◆ plus_kids()

VBitSet com.cliffc.aa.type.Bits< B extends Bits< B >.Tree< B extends Bits< B >.plus_kids ( Bits< B >  bits)

Definition at line 483 of file Bits.java.

483  {
484  VBitSet bs = new VBitSet();
485  for( int i : bits )
486  if( i != 0 )
487  _plus_kids(bs,i);
488  return bs;
489  }

References com.cliffc.aa.type.Bits< B extends Bits< B >.Tree< B extends Bits< B >._plus_kids(), and com.cliffc.aa.type.Bits< B extends Bits< B >.bits().

Here is the call graph for this function:

◆ reset_to_init0()

void com.cliffc.aa.type.Bits< B extends Bits< B >.Tree< B extends Bits< B >.reset_to_init0 ( )
package

Definition at line 475 of file Bits.java.

475  {
476  for( int i=0; i<_kids.length; i++ )
477  if( _kids[i] != null )
478  _kids[i][0] = i<_init.length ? _init[i] : 1;
479  }

References com.cliffc.aa.type.Bits< B extends Bits< B >.Tree< B extends Bits< B >._init, and com.cliffc.aa.type.Bits< B extends Bits< B >.Tree< B extends Bits< B >._kids.

◆ split()

int com.cliffc.aa.type.Bits< B extends Bits< B >.Tree< B extends Bits< B >.split ( int  par)
package

Definition at line 433 of file Bits.java.

433  {
434  // See if we have an existing bit
435  if( par < _kids.length ) { // This parent has kids already
436  int[] kids = _kids[par]; //
437  if( kids != null ) {
438  int klen = kids[0]; // Number of kids already, 1-based
439  if( klen < kids.length ) { // Room for more in array?
440  int bit = kids[klen];
441  if( bit != 0 ) { // Pre-allocated kid from prior test?
442  assert _pars[bit] == par; // Then parent must already be preallocated
443  kids[0] = klen+1;
444  return bit;
445  }
446  }
447  }
448  }
449  // Need a new bit
450  int bit = _cnt++; // Next available bit number
451 
452  // Make space in the parents array to hold the parent of 'bit'
453  while( bit >= _pars.length ) _pars = Arrays.copyOf(_pars,_pars.length<<1);
454  assert _pars[bit]==0;
455  _pars[bit] = par;
456  // Make space in the kids array to hold the children of 'par'
457  while( par >= _kids.length ) _kids = Arrays.copyOf(_kids,_kids.length<<1);
458  int[] kids = _kids[par]; // All the children of 'par'
459  if( kids==null ) _kids[par] = kids = new int[]{1};
460  int klen = kids[0]; // 1-based number of children. '1' means 'no children'
461  if( klen == kids.length ) // Make space as needed
462  _kids[par] = kids = Arrays.copyOf(kids,klen<<1);
463  kids[klen] = bit; // Insert new child of parent
464  kids[0] = klen+1; // Bump count of children
465  return bit;
466  }

References com.cliffc.aa.type.Bits< B extends Bits< B >.Tree< B extends Bits< B >._cnt, com.cliffc.aa.type.Bits< B extends Bits< B >.Tree< B extends Bits< B >._kids, and com.cliffc.aa.type.Bits< B extends Bits< B >.Tree< B extends Bits< B >._pars.

◆ toString() [1/2]

String com.cliffc.aa.type.Bits< B extends Bits< B >.Tree< B extends Bits< B >.toString ( )

Definition at line 420 of file Bits.java.

420 { return toString(new SB(),1).toString(); }

References com.cliffc.aa.type.Bits< B extends Bits< B >.Tree< B extends Bits< B >.toString().

Referenced by com.cliffc.aa.type.Bits< B extends Bits< B >.Tree< B extends Bits< B >.toString().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toString() [2/2]

SB com.cliffc.aa.type.Bits< B extends Bits< B >.Tree< B extends Bits< B >.toString ( SB  sb,
int  i 
)
private

Definition at line 421 of file Bits.java.

421  {
422  sb.i().p(i).nl();
423  if( is_parent(i) ) {
424  sb.ii(1);
425  for( int j=1; j<_kids[i][0]; j++ )
426  toString(sb,_kids[i][j]);
427  sb.di(1);
428  }
429  return sb;
430  }

References com.cliffc.aa.type.Bits< B extends Bits< B >.Tree< B extends Bits< B >._kids, com.cliffc.aa.util.SB.di(), com.cliffc.aa.util.SB.i(), com.cliffc.aa.util.SB.ii(), com.cliffc.aa.type.Bits< B extends Bits< B >.Tree< B extends Bits< B >.is_parent(), com.cliffc.aa.util.SB.nl(), com.cliffc.aa.util.SB.p(), and com.cliffc.aa.type.Bits< B extends Bits< B >.Tree< B extends Bits< B >.toString().

Here is the call graph for this function:

Member Data Documentation

◆ _cnt

int com.cliffc.aa.type.Bits< B extends Bits< B >.Tree< B extends Bits< B >._cnt = 1
package

◆ _init

◆ _kids

◆ _pars


The documentation for this class was generated from the following file:
com.cliffc.aa.type.Bits.bits
static long[] bits(int b)
Definition: Bits.java:283
com.cliffc.aa.type.Bits.Tree.toString
String toString()
Definition: Bits.java:420
com.cliffc.aa.type.Bits.Tree.is_parent
boolean is_parent(int idx)
Definition: Bits.java:410
com.cliffc.aa.type.Bits.Tree.parent
int parent(int kid)
Definition: Bits.java:409
com.cliffc.aa.type.Bits.Tree._init
int[] _init
Definition: Bits.java:407
com.cliffc.aa.type.Bits.Tree._cnt
int _cnt
Definition: Bits.java:403
com.cliffc.aa.type.Bits.idx
static int idx(long i)
Definition: Bits.java:199
com.cliffc.aa.type.Bits.Tree._kids
int[][] _kids
Definition: Bits.java:406
com.cliffc.aa.type.Bits.Tree._pars
int[] _pars
Definition: Bits.java:405
com.cliffc.aa.type.Bits.Tree._plus_kids
void _plus_kids(VBitSet bs, int i)
Definition: Bits.java:490