Javolution 6.0.0 java
javolution.util.internal.table.FractalTableImpl Class Reference
Collaboration diagram for javolution.util.internal.table.FractalTableImpl:
[legend]

Public Member Functions

 FractalTableImpl ()
 
 FractalTableImpl (int shift)
 
 FractalTableImpl (int shift, Object[] data, int offset)
 
int capacity ()
 
Object get (int index)
 
Object set (int index, Object element)
 
void shiftLeft (Object inserted, int last, int length)
 
void shiftRight (Object inserted, int first, int length)
 
FractalTableImpl upsize ()
 

Package Attributes

int offset
 

Static Package Attributes

static final int BASE_CAPACITY_MIN = 16
 
static final int SHIFT = 8
 

Private Member Functions

void copyTo (FractalTableImpl that)
 
FractalTableImpl allocate (int i)
 
FractalTableImpl F (int i)
 

Private Attributes

Object[] data
 
final int shift
 

Static Private Attributes

static final int BASE_CAPACITY_MAX = 1 << SHIFT
 

Detailed Description

A fractal-based table with fast insertion/deletion capabilities regardless of the collection size. It is based on a fractal structure with self-similar patterns at any scale (large tables have the same structure as smaller tables which have similar structure as even smaller tables and so on).

Definition at line 19 of file FractalTableImpl.java.

Constructor & Destructor Documentation

◆ FractalTableImpl() [1/3]

javolution.util.internal.table.FractalTableImpl.FractalTableImpl ( )

Definition at line 35 of file FractalTableImpl.java.

35  {
36  this.shift = 0;
37  data = new Object[BASE_CAPACITY_MIN];
38  }

References javolution.util.internal.table.FractalTableImpl.BASE_CAPACITY_MIN, and javolution.util.internal.table.FractalTableImpl.data.

Referenced by javolution.util.internal.table.FractalTableImpl.allocate(), javolution.util.internal.table.FractalTableImpl.F(), javolution.util.internal.table.FractalTableImpl.get(), and javolution.util.internal.table.FractalTableImpl.upsize().

Here is the caller graph for this function:

◆ FractalTableImpl() [2/3]

javolution.util.internal.table.FractalTableImpl.FractalTableImpl ( int  shift)

Definition at line 40 of file FractalTableImpl.java.

40  {
41  this.shift = shift;
42  data = new Object[2];
43  }

References javolution.util.internal.table.FractalTableImpl.data, and javolution.util.internal.table.FractalTableImpl.shift.

◆ FractalTableImpl() [3/3]

javolution.util.internal.table.FractalTableImpl.FractalTableImpl ( int  shift,
Object[]  data,
int  offset 
)

Member Function Documentation

◆ allocate()

FractalTableImpl javolution.util.internal.table.FractalTableImpl.allocate ( int  i)
private

Definition at line 160 of file FractalTableImpl.java.

160  {
162  new Object[1 << SHIFT], 0);
163  data[i] = fractal;
164  return fractal;
165  }

References javolution.util.internal.table.FractalTableImpl.data, javolution.util.internal.table.FractalTableImpl.FractalTableImpl(), javolution.util.internal.table.FractalTableImpl.SHIFT, and javolution.util.internal.table.FractalTableImpl.shift.

Referenced by javolution.util.internal.table.FractalTableImpl.F().

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

◆ capacity()

int javolution.util.internal.table.FractalTableImpl.capacity ( )

Definition at line 51 of file FractalTableImpl.java.

51  {
52  // Reports lower capacity to ensure that there is no fractal holding
53  // wrapping data (head and tail in the same fractal).
54  return (data.length - 1) << shift;
55  }

References javolution.util.internal.table.FractalTableImpl.data, and javolution.util.internal.table.FractalTableImpl.shift.

Referenced by javolution.util.internal.table.FastTableImpl< E >.upsize().

Here is the caller graph for this function:

◆ copyTo()

void javolution.util.internal.table.FractalTableImpl.copyTo ( FractalTableImpl  that)
private

Definition at line 147 of file FractalTableImpl.java.

147  {
148  int n = MathLib.min(this.data.length, that.data.length);
149  offset &= (data.length << shift) - 1; // Makes it positive.
150  int o = offset >> shift;
151  if ((o + n) > data.length) { // Wrapping.
152  int w = (o + n) - data.length;
153  n -= w;
154  System.arraycopy(data, 0, that.data, n, w);
155  }
156  System.arraycopy(data, o, that.data, 0, n);
157  that.offset = offset - (o << shift);
158  }

References javolution.util.internal.table.FractalTableImpl.data, javolution.lang.MathLib.min(), javolution.util.internal.table.FractalTableImpl.offset, and javolution.util.internal.table.FractalTableImpl.shift.

Referenced by javolution.util.internal.table.FractalTableImpl.upsize().

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

◆ F()

FractalTableImpl javolution.util.internal.table.FractalTableImpl.F ( int  i)
private

Definition at line 167 of file FractalTableImpl.java.

167  {
169  return (table != null) ? table : allocate(i);
170  }

References javolution.util.internal.table.FractalTableImpl.allocate(), javolution.util.internal.table.FractalTableImpl.data, and javolution.util.internal.table.FractalTableImpl.FractalTableImpl().

Referenced by javolution.util.internal.table.FractalTableImpl.set(), javolution.util.internal.table.FractalTableImpl.shiftLeft(), javolution.util.internal.table.FractalTableImpl.shiftRight(), and javolution.util.internal.table.FractalTableImpl.upsize().

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

◆ get()

Object javolution.util.internal.table.FractalTableImpl.get ( int  index)

Definition at line 57 of file FractalTableImpl.java.

57  {
58  Object fractal = data[((index + offset) >> shift) & (data.length - 1)];
59  return (shift == 0) ? fractal : ((FractalTableImpl) fractal).get(index
60  + offset);
61  }

References javolution.util.internal.table.FractalTableImpl.data, javolution.util.internal.table.FractalTableImpl.FractalTableImpl(), javolution.util.internal.table.FractalTableImpl.offset, and javolution.util.internal.table.FractalTableImpl.shift.

Referenced by javolution.util.internal.table.FastTableImpl< E >.get(), javolution.util.internal.table.FastTableImpl< E >.IteratorImpl.next(), javolution.util.internal.table.FastTableImpl< E >.remove(), javolution.util.internal.table.FractalTableImpl.shiftRight(), and javolution.util.internal.table.FastTableImpl< E >.writeObject().

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

◆ set()

Object javolution.util.internal.table.FractalTableImpl.set ( int  index,
Object  element 
)

Definition at line 63 of file FractalTableImpl.java.

63  {
64  int i = ((index + offset) >> shift) & (data.length - 1);
65  if (shift != 0) return F(i).set(index + offset, element);
66  Object previous = data[i];
67  data[i] = element;
68  return previous;
69  }

References javolution.util.internal.table.FractalTableImpl.data, javolution.util.internal.table.FractalTableImpl.F(), javolution.util.internal.table.FractalTableImpl.offset, javolution.util.internal.table.FractalTableImpl.set(), and javolution.util.internal.table.FractalTableImpl.shift.

Referenced by javolution.util.internal.table.FastTableImpl< E >.addFirst(), javolution.util.internal.table.FastTableImpl< E >.addLast(), javolution.util.internal.table.FastTableImpl< E >.removeFirst(), javolution.util.internal.table.FastTableImpl< E >.removeLast(), javolution.util.internal.table.FractalTableImpl.set(), javolution.util.internal.table.FastTableImpl< E >.set(), javolution.util.internal.table.FractalTableImpl.shiftLeft(), and javolution.util.internal.table.FractalTableImpl.shiftRight().

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

◆ shiftLeft()

void javolution.util.internal.table.FractalTableImpl.shiftLeft ( Object  inserted,
int  last,
int  length 
)

Shifts the specified elements(]last - length, last] modulo capacity) one position to the left. No shift if length (modulo capacity) is zero.

Definition at line 73 of file FractalTableImpl.java.

73  {
74  int mask = (data.length << shift) - 1;
75  int tail = (last + offset) & mask;
76  int head = (last + offset - length) & mask;
77  if (shift == 0) {
78  int n = tail - head;
79  if (head > tail) { // Wrapping
80  System.arraycopy(data, head + 1, data, head, mask - head);
81  data[mask] = data[0];
82  n = tail;
83  }
84  System.arraycopy(data, tail - n + 1, data, tail - n, n);
85  data[tail] = inserted;
86  } else if ((head <= tail) && ((head >> shift) == (tail >> shift))) { // Shift local to inner table.
87  F(head >> shift).shiftLeft(inserted, tail, length); // (no wrapping).
88  } else {
89  int low = head >> shift;
90  int high = (low != data.length - 1) ? low + 1 : 0;
91  F(low).shiftLeft(F(high).get(0), -1, mask - head);
92  while (high != (tail >> shift)) {
93  low = high;
94  high = (low != data.length - 1) ? low + 1 : 0;
95  F(low).offset++; // Full shift left.
96  F(low).set(-1, F(high).get(0));
97  }
98  F(high).shiftLeft(inserted, tail, tail);
99  }
100  }

References javolution.util.internal.table.FractalTableImpl.data, javolution.util.internal.table.FractalTableImpl.F(), javolution.util.internal.table.FractalTableImpl.offset, javolution.util.internal.table.FractalTableImpl.set(), javolution.util.internal.table.FractalTableImpl.shift, and javolution.util.internal.table.FractalTableImpl.shiftLeft().

Referenced by javolution.util.internal.table.FastTableImpl< E >.add(), javolution.util.internal.table.FastTableImpl< E >.remove(), and javolution.util.internal.table.FractalTableImpl.shiftLeft().

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

◆ shiftRight()

void javolution.util.internal.table.FractalTableImpl.shiftRight ( Object  inserted,
int  first,
int  length 
)

Shifts the specified element ([first, first + length[ modulo capacity) one position to the right. No shift if length (modulo capacity) is zero.

Definition at line 104 of file FractalTableImpl.java.

104  {
105  int mask = (data.length << shift) - 1;
106  int head = (first + offset) & mask;
107  int tail = (first + offset + length) & mask;
108  if (shift == 0) {
109  int n = tail - head;
110  if (head > tail) { // Wrapping
111  System.arraycopy(data, 0, data, 1, tail);
112  data[0] = data[mask];
113  n = mask - head;
114  }
115  System.arraycopy(data, head, data, head + 1, n);
116  data[head] = inserted;
117  } else if ((head <= tail) && ((head >> shift) == (tail >> shift))) { // Shift local to inner table.
118  F(head >> shift).shiftRight(inserted, head, length); // (no wrapping).
119  } else {
120  int high = tail >> shift;
121  int low = (high != 0) ? high - 1 : data.length - 1;
122  F(high).shiftRight(F(low).get(-1), 0, tail);
123  while (low != (head >> shift)) {
124  high = low;
125  low = (high != 0) ? high - 1 : data.length - 1;
126  F(high).offset--; // Full shift right.
127  F(high).set(0, F(low).get(-1));
128  }
129  F(low).shiftRight(inserted, head, mask - head);
130  }
131  }

References javolution.util.internal.table.FractalTableImpl.data, javolution.util.internal.table.FractalTableImpl.F(), javolution.util.internal.table.FractalTableImpl.get(), javolution.util.internal.table.FractalTableImpl.offset, javolution.util.internal.table.FractalTableImpl.set(), javolution.util.internal.table.FractalTableImpl.shift, and javolution.util.internal.table.FractalTableImpl.shiftRight().

Referenced by javolution.util.internal.table.FastTableImpl< E >.add(), javolution.util.internal.table.FastTableImpl< E >.remove(), and javolution.util.internal.table.FractalTableImpl.shiftRight().

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

◆ upsize()

FractalTableImpl javolution.util.internal.table.FractalTableImpl.upsize ( )

Definition at line 133 of file FractalTableImpl.java.

133  {
134  if (data.length >= BASE_CAPACITY_MAX) { // Creates outer fractal.
136  copyTo(table.F(0));
137  return table;
138  } else {
139  FractalTableImpl table =
140  new FractalTableImpl(shift, new Object[data.length << 1], 0);
141  copyTo(table);
142  return table;
143  }
144  }

References javolution.util.internal.table.FractalTableImpl.BASE_CAPACITY_MAX, javolution.util.internal.table.FractalTableImpl.copyTo(), javolution.util.internal.table.FractalTableImpl.data, javolution.util.internal.table.FractalTableImpl.F(), javolution.util.internal.table.FractalTableImpl.FractalTableImpl(), javolution.util.internal.table.FractalTableImpl.SHIFT, and javolution.util.internal.table.FractalTableImpl.shift.

Referenced by javolution.util.internal.table.FastTableImpl< E >.upsize().

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

Member Data Documentation

◆ BASE_CAPACITY_MAX

final int javolution.util.internal.table.FractalTableImpl.BASE_CAPACITY_MAX = 1 << SHIFT
staticprivate

◆ BASE_CAPACITY_MIN

final int javolution.util.internal.table.FractalTableImpl.BASE_CAPACITY_MIN = 16
staticpackage

◆ data

◆ offset

◆ SHIFT

final int javolution.util.internal.table.FractalTableImpl.SHIFT = 8
staticpackage

◆ shift


The documentation for this class was generated from the following file:
javolution.util.internal.table.FractalTableImpl.set
Object set(int index, Object element)
Definition: FractalTableImpl.java:63
javolution.util.internal.table.FractalTableImpl.data
Object[] data
Definition: FractalTableImpl.java:30
javolution.util.internal.table.FractalTableImpl.F
FractalTableImpl F(int i)
Definition: FractalTableImpl.java:167
javolution.util.internal.table.FractalTableImpl.copyTo
void copyTo(FractalTableImpl that)
Definition: FractalTableImpl.java:147
javolution.util.internal.table.FractalTableImpl.BASE_CAPACITY_MIN
static final int BASE_CAPACITY_MIN
Definition: FractalTableImpl.java:21
javolution.util.internal.table.FractalTableImpl.get
Object get(int index)
Definition: FractalTableImpl.java:57
javolution.util.internal.table.FractalTableImpl.shift
final int shift
Definition: FractalTableImpl.java:33
javolution.util.internal.table.FractalTableImpl.FractalTableImpl
FractalTableImpl()
Definition: FractalTableImpl.java:35
javolution.util.internal.table.FractalTableImpl.BASE_CAPACITY_MAX
static final int BASE_CAPACITY_MAX
Definition: FractalTableImpl.java:23
javolution.util.internal.table.FractalTableImpl.allocate
FractalTableImpl allocate(int i)
Definition: FractalTableImpl.java:160
javolution.util.internal.table.FractalTableImpl.shiftRight
void shiftRight(Object inserted, int first, int length)
Definition: FractalTableImpl.java:104
javolution.util.internal.table.FractalTableImpl.shiftLeft
void shiftLeft(Object inserted, int last, int length)
Definition: FractalTableImpl.java:73
javolution.util.internal.table.FractalTableImpl.offset
int offset
Definition: FractalTableImpl.java:26
javolution.util.internal.table.FractalTableImpl.SHIFT
static final int SHIFT
Definition: FractalTableImpl.java:22