eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'CompactHierarchicalItem':



Class: CompactHierarchicalItem



rev: 1.5 date: 2016/05/04 17:09:04
user: cg
file: CompactHierarchicalItem.st directory: libwidg2
module: stx stc-classLibrary: libwidg2
Claus Gittinger


Compact Hierarchical Items are a new, tuned and optimized version of the original
hierarchical item, which suffers various problems:
    1) the old item did not store the model, which in many situations leads to very
       poor performance (it walks along the super-item hierarchy to find the model,
       which makes many algorithms O(n^2) instead of O(n)
    2) it keeps individual width/height information, where this could be shared if
       many items have the same extent.
    3) it uses separate width/height instvars, where this information can be stored more compact
       in single integer (using bit-masks)
    4) it uses a separate boolean for the isExpanded, which could be encoded more space efficient as a single bit

Problems 2-4 only apply to huge trees with (say 100s of thousands of items). Such big trees are encountered
for example in the expecco activity log.

This class solves those issues:
    - it uses a compact width/height representation (bit masks in an integer), for
      items within a reasonable size (0 to 64k pixels wide, 0 to 16k pixels high).
    - falls back to a separate width/height holding object, if ever exceeded (which is unlikely)

    - it encodes the expanded state in a single bit

    - it uses the saved slot to allow for the model to be kept locally

Notice, that in order to be backward compatible, the cached width and height fields can
take integer values AND nil. Nil is typically used to mark an invalid cached value.
Here, the nil case is encoded in the bitField as all-ones (max value).

Before changing the superclass of your existing HierarchicalItem subclass, make sure that the subclass does not access 
the instvars isExpanded, width and heigh directly.
Instead, use the getters isExpanded, width and height and the setters setExpanded:, width: and height:

Related information:


Class protocol:

class initialization
o  initialize
self assert:(ShiftHeight + (MaskHeight highBit)) < 31.

Instance protocol:

o  fetchModel
returns the hierachicalList model or nil.
This is a stupid implementation here, in that the top-item's parent is assumed to
be the model of the tree, and that is returned.
This saves a slot in every node, but makes some algorithms O(n*log n) or even O(n^2).
So be aware of the performance penalty

o  model
returns the hierachicalList model or nil.
This fixes the stupid implementation of the old HierarchicalItem,
by caching the fetched model (behaving the same, if there is no model)

o  makeWidthAndHeightUnknown
invalidate any cached with/height information

o  setExpanded: aBoolean
set expanded flag without any computation or notification

o  getWidthAndHeightOn: aGC
fetch the width and height from my label, if it is to be displayed on aGC

o  height
return the cached height

o  height: h
encode the cached height, preserving the isExpanded state

o  heightOn: aGC
return the height of the receiver, if it is to be displayed on aGC

o  isExpanded

o  width
return the cached height

o  width: w
encode the cached width, preserving the isExpanded state

o  width: w height: h
encode width and height, preserving the isExpanded state

o  width: w height: h isExpanded: expanded
encode width and height, and isExpanded state

o  widthOn: aGC
return the width of the receiver, if it is to be displayed on aGC

Private classes:


ST/X; WebServer 1.663 at exept.de:8081; Fri, 20 Jul 2018 06:27:32 GMT