Skip to content

Commit

Permalink
Renewing of the PerfectHash values due to new properties of diagonal …
Browse files Browse the repository at this point in the history
…and antidiagonal eclipse-birt#1224 (eclipse-birt#1264)

* renewing of the PerfectHash values due to the new properties of diagonal
and antidiagonal eclipse-birt#1224

* Update token.gperf

Fixed incorrect comment about gperf command line options

* README.md file of PerfectHash and new launch file of all engine tests

* Update of README.md

* Update README.md

---------

Co-authored-by: Henning von Bargen <h.vonbargen@t-p.com>
  • Loading branch information
speckyspooky and hvbtup committed Apr 18, 2023
1 parent 63f06dd commit cad3711
Show file tree
Hide file tree
Showing 6 changed files with 419 additions and 339 deletions.
4 changes: 2 additions & 2 deletions build/org.eclipse.birt.target/BIRT Model Test (Engine).launch
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<stringAttribute key="location" value="${workspace_loc}/../junit-workspace"/>
<booleanAttribute key="org.eclipse.debug.core.ATTR_FORCE_SYSTEM_CONSOLE_ENCODING" value="false"/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/org.eclipse.birt.report.engine.tests/test/org/eclipse/birt/report/engine/ir/EngineIRIOTest.java"/>
<listEntry value="/org.eclipse.birt.report.engine.tests/test/org/eclipse/birt/report/engine/AllTests.java"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="1"/>
Expand All @@ -34,7 +34,7 @@
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_ATTR_USE_ARGFILE" value="false"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_SHOW_CODEDETAILS_IN_EXCEPTION_MESSAGES" value="true"/>
<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.birt.report.engine.ir.EngineIRIOTest"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.birt.report.engine.AllTests"/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.birt.report.engine.tests"/>
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,20 @@ public class PerfectHash {

final static int MIN_WORD_LENGTH = 5;

final static int MAX_WORD_LENGTH = 25;
final static int MAX_WORD_LENGTH = 26;

final static int MIN_HASH_VALUE = 10;
final static int MIN_HASH_VALUE = 11;

final static int MAX_HASH_VALUE = 111;
final static int MAX_HASH_VALUE = 174;

/* maximum key range = 102, duplicates = 0 */
/* maximum key range = 164, duplicates = 0 */

static int asso_values[] = { 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112,
112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112,
112, 112, 112, 112, 112, 112, 112, 45, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112,
112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112,
112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 52, 5, 0, 0, 15, 40, 20, 0,
40, 112, 15, 0, 20, 5, 0, 5, 112, 5, 40, 0, 112, 15, 45, 30, 36, 112, 112, 112, 112, 112, 112, 112, 112,
112, 112, 112, 112, 112, 112 };
static int asso_values[] = { 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175,
175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175,
175, 175, 175, 175, 175, 175, 175, 75, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175,
175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175,
175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 105, 0, 30, 5, 20, 55, 10,
5, 50, 175, 0, 100, 0, 20, 0, 10, 175, 0, 60, 0, 175, 0, 30, 45, 65, 175, 175, 175, 175, 175, 175 };

public static int hash(String str) {
int hashValue = str.length();
Expand All @@ -61,60 +60,65 @@ public static int hash(String str) {
return hashValue + asso_values[str.charAt(str.length() - 1)];
}

static int lengthtable[] = { 5, 11, 11, 12, 13, 9, 11, 17, 16, 17, 18, 19, 10, 16, 18, 19, 11, 12, 14, 10, 11, 18,
19, 10, 6, 12, 5, 16, 7, 11, 12, 13, 21, 17, 13, 14, 16, 21, 8, 9, 10, 16, 17, 13, 14, 16, 17, 21, 14, 16,
7, 11, 17, 14, 6, 11, 17, 16, 14, 12, 11, 21, 22, 21, 21, 21, 26, 25, 25, 25 };

static String wordlist[] = { "color" /* hash value = 10, index = 0 */,
"data-format" /* hash value = 11, index = 1 */, "line-height" /* hash value = 16, index = 2 */,
"padding-left" /* hash value = 17, index = 3 */, "padding-right" /* hash value = 18, index = 4 */,
"direction" /* hash value = 19, index = 5 */, "padding-top" /* hash value = 21, index = 6 */,
"background-height" /* hash value = 22, index = 7 */, "background-color" /* hash value = 26, index = 8 */,
"background-repeat" /* hash value = 27, index = 9 */,
"border-right-width" /* hash value = 28, index = 10 */,
"border-bottom-width" /* hash value = 29, index = 11 */, "can-shrink" /* hash value = 30, index = 12 */,
"border-top-color" /* hash value = 31, index = 13 */,
"border-right-color" /* hash value = 33, index = 14 */,
"border-bottom-color" /* hash value = 34, index = 15 */, "margin-left" /* hash value = 36, index = 16 */,
"margin-right" /* hash value = 37, index = 17 */, "padding-bottom" /* hash value = 39, index = 18 */,
"margin-top" /* hash value = 40, index = 19 */, "text-indent" /* hash value = 41, index = 20 */,
"border-right-style" /* hash value = 43, index = 21 */,
"border-bottom-style" /* hash value = 44, index = 22 */, "text-align" /* hash value = 45, index = 23 */,
"height" /* hash value = 46, index = 24 */, "number-align" /* hash value = 47, index = 25 */,
"width" /* hash value = 50, index = 26 */, "text-linethrough" /* hash value = 51, index = 27 */,
"orphans" /* hash value = 52, index = 28 */, "font-weight" /* hash value = 56, index = 29 */,
"font-variant" /* hash value = 57, index = 30 */, "margin-bottom" /* hash value = 58, index = 31 */,
"background-position-x" /* hash value = 61, index = 32 */,
"page-break-before" /* hash value = 62, index = 33 */, "text-overline" /* hash value = 63, index = 34 */,
"text-transform" /* hash value = 64, index = 35 */, "background-width" /* hash value = 66, index = 36 */,
"background-position-y" /* hash value = 67, index = 37 */, "overflow" /* hash value = 68, index = 38 */,
"font-size" /* hash value = 69, index = 39 */, "font-style" /* hash value = 70, index = 40 */,
"border-top-width" /* hash value = 71, index = 41 */, "border-left-width" /* hash value = 72, index = 42 */,
"show-if-blank" /* hash value = 73, index = 43 */, "letter-spacing" /* hash value = 74, index = 44 */,
"background-image" /* hash value = 76, index = 45 */, "border-left-color" /* hash value = 77, index = 46 */,
"background-attachment" /* hash value = 78, index = 47 */,
"vertical-align" /* hash value = 79, index = 48 */, "border-top-style" /* hash value = 81, index = 49 */,
"display" /* hash value = 83, index = 50 */, "master-page" /* hash value = 86, index = 51 */,
"border-left-style" /* hash value = 87, index = 52 */, "visible-format" /* hash value = 89, index = 53 */,
"widows" /* hash value = 91, index = 54 */, "font-family" /* hash value = 92, index = 55 */,
"page-break-inside" /* hash value = 97, index = 56 */, "page-break-after" /* hash value = 98, index = 57 */,
"text-underline" /* hash value = 99, index = 58 */, "word-spacing" /* hash value = 102, index = 59 */,
"white-space" /* hash value = 111, index = 60 */, "background-image-type" /* hash value = ??, index = 61 */,
"border-diagonal-number" /* hash value = ??, index = 62 */,
"border-diagonal-width" /* hash value = ??, index = 63 */,
"border-diagonal-color" /* hash value = ??, index = 64 */,
"border-diagonal-style" /* hash value = ??, index = 65 */,
"border-antidiagonal-number" /* hash value = ??, index = 66 */,
"border-antidiagonal-width" /* hash value = ??, index = 67 */,
"border-antidiagonal-color" /* hash value = ??, index = 68 */,
"border-antidiagonal-style" /* hash value = ??, index = 69 */
static int lengthtable[] = { 11, 12, 13, 11, 18, 19, 10, 21, 22, 18, 19, 21, 12, 14, 25, 26, 13, 9, 25, 11, 18, 19,
21, 5, 16, 17, 25, 16, 17, 11, 17, 8, 14, 10, 6, 12, 16, 12, 14, 10, 16, 7, 16, 14, 11, 12, 11, 17, 13, 16,
17, 13, 6, 9, 10, 21, 17, 11, 17, 16, 21, 21, 14, 11, 5, 7, 16, 11, 21, 14 };

static String wordlist[] = { "margin-left" /* hash value = 11, index = 0 */,
"margin-right" /* hash value = 12, index = 1 */, "margin-bottom" /* hash value = 13, index = 2 */,
"data-format" /* hash value = 16, index = 3 */, "border-right-color" /* hash value = 18, index = 4 */,
"border-bottom-color" /* hash value = 19, index = 5 */, "margin-top" /* hash value = 20, index = 6 */,
"border-diagonal-color" /* hash value = 21, index = 7 */,
"border-diagonal-number" /* hash value = 22, index = 8 */,
"border-right-width" /* hash value = 23, index = 9 */,
"border-bottom-width" /* hash value = 24, index = 10 */,
"border-diagonal-width" /* hash value = 26, index = 11 */, "padding-left" /* hash value = 27, index = 12 */,
"padding-bottom" /* hash value = 29, index = 13 */,
"border-antidiagonal-color" /* hash value = 30, index = 14 */,
"border-antidiagonal-number" /* hash value = 31, index = 15 */,
"padding-right" /* hash value = 33, index = 16 */, "direction" /* hash value = 34, index = 17 */,
"border-antidiagonal-width" /* hash value = 35, index = 18 */,
"padding-top" /* hash value = 36, index = 19 */, "border-right-style" /* hash value = 38, index = 20 */,
"border-bottom-style" /* hash value = 39, index = 21 */,
"border-diagonal-style" /* hash value = 41, index = 22 */, "width" /* hash value = 45, index = 23 */,
"border-top-color" /* hash value = 46, index = 24 */, "background-repeat" /* hash value = 47, index = 25 */,
"border-antidiagonal-style" /* hash value = 50, index = 26 */,
"border-top-width" /* hash value = 51, index = 27 */, "background-height" /* hash value = 52, index = 28 */,
"text-indent" /* hash value = 56, index = 29 */, "page-break-before" /* hash value = 57, index = 30 */,
"overflow" /* hash value = 58, index = 31 */, "text-transform" /* hash value = 59, index = 32 */,
"can-shrink" /* hash value = 60, index = 33 */, "height" /* hash value = 61, index = 34 */,
"word-spacing" /* hash value = 62, index = 35 */, "text-linethrough" /* hash value = 66, index = 36 */,
"number-align" /* hash value = 72, index = 37 */, "visible-format" /* hash value = 74, index = 38 */,
"text-align" /* hash value = 75, index = 39 */, "background-color" /* hash value = 76, index = 40 */,
"orphans" /* hash value = 77, index = 41 */, "background-width" /* hash value = 81, index = 42 */,
"vertical-align" /* hash value = 84, index = 43 */, "font-weight" /* hash value = 86, index = 44 */,
"font-variant" /* hash value = 87, index = 45 */, "master-page" /* hash value = 91, index = 46 */,
"border-left-color" /* hash value = 92, index = 47 */, "show-if-blank" /* hash value = 93, index = 48 */,
"border-top-style" /* hash value = 96, index = 49 */, "border-left-width" /* hash value = 97, index = 50 */,
"text-overline" /* hash value = 98, index = 51 */, "widows" /* hash value = 101, index = 52 */,
"font-size" /* hash value = 104, index = 53 */, "font-style" /* hash value = 105, index = 54 */,
"background-position-x" /* hash value = 106, index = 55 */,
"page-break-inside" /* hash value = 107, index = 56 */, "white-space" /* hash value = 111, index = 57 */,
"border-left-style" /* hash value = 112, index = 58 */,
"background-image" /* hash value = 116, index = 59 */,
"background-image-type" /* hash value = 121, index = 60 */,
"background-position-y" /* hash value = 126, index = 61 */,
"text-underline" /* hash value = 129, index = 62 */, "line-height" /* hash value = 131, index = 63 */,
"color" /* hash value = 135, index = 64 */, "display" /* hash value = 137, index = 65 */,
"page-break-after" /* hash value = 141, index = 66 */, "font-family" /* hash value = 151, index = 67 */,
"background-attachment" /* hash value = 156, index = 68 */,
"letter-spacing" /* hash value = 174, index = 69 */
};

static short lookup[] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, -1, -1, -1, -1, 2, 3, 4, 5, -1, 6, 7, -1,
-1, -1, 8, 9, 10, 11, 12, 13, -1, 14, 15, -1, 16, 17, -1, 18, 19, 20, -1, 21, 22, 23, 24, 25, -1, -1, 26,
27, 28, -1, -1, -1, 29, 30, 31, -1, -1, 32, 33, 34, 35, -1, 36, 37, 38, 39, 40, 41, 42, 43, 44, -1, 45, 46,
47, 48, -1, 49, -1, 50, -1, -1, 51, 52, -1, 53, -1, 54, 55, -1, -1, -1, -1, 56, 57, 58, -1, -1, 59, -1, -1,
-1, -1, -1, -1, -1, -1, 60, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
public static int lookup[] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, -1, -1, 3, -1, 4, 5, 6, 7, 8, 9,
10, -1, 11, 12, -1, 13, 14, 15, -1, 16, 17, 18, 19, -1, 20, 21, -1, 22, -1, -1, -1, 23, 24, 25, -1, -1, 26,
27, 28, -1, -1, -1, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, 36, -1, -1, -1, -1, -1, 37, -1, 38, 39, 40, 41,
-1, -1, -1, 42, -1, -1, 43, -1, 44, 45, -1, -1, -1, 46, 47, 48, -1, -1, 49, 50, 51, -1, -1, 52, -1, -1, 53,
54, 55, 56, -1, -1, -1, 57, 58, -1, -1, -1, 59, -1, -1, -1, -1, 60, -1, -1, -1, -1, 61, -1, -1, 62, -1, 63,
-1, -1, -1, 64, -1, 65, -1, -1, -1, 66, -1, -1, -1, -1, -1, -1, -1, -1, -1, 67, -1, -1, -1, -1, 68, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 69

};

public static int in_word_set(String str) {
int len = str.length();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Eclipse BIRT
Introduction to generate new version of the PerfectHash class and the corresponding StyleConstants.

## Reason
Accessing properties is optimized in BIRT.
The idea is to avoid costly string comparisons if possible.
To achieve this goal, BIRT uses a perfect hash and a utility class.
These are implemented in two classes:
* PerfectHash.java
* StyleConstants.java

In order to add new properties, these classes must be extended. The process is described below.
After the whole process both files have to include the properties with the same index numbers at property side.

## Processing steps
The target of the following steps is to create the correct versions of `PerfectHash.java` and `StyleConstants.java`.
The files are located at the directory:
* engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/css/engine:

Additional files which are required for the correct creation:
* `token.gperf` - input file, ASCII encoding, Linux line ending required
* `token.cpp` - generated source file like base template for PerfectHash.java

### Step 1: Create the word-list of properties based on `PerfectHash.java`
* Copy the wordlist from PerfectHash.java into a text editor
* Sort the word list and modify it with a good editor (e.g. Notepad++)
* (For new properties, add the property names to the text)
* Save the text file ASCII-encoded as `token.gperf`. Be aware that the line end is linux based end (line feed = \n).
* Restore the comment lines at the top of the file from the original `token.perf`.

### Step 2: Build the source `template token.cpp`
* Required is the build of the intermediate file `token.cpp` with a working version of the GNU gperf utility.
* Under MS Windows one option is [cygwin] (https://www.cygwin.com/install.html). This tool is an Unix terminal command line simulator.
* Open a command line and CD into the directory containing `token.gperf`
* Execute the following command line:

`gperf -d -7 -l -D -L C++ token.gperf > token.cpp`

* This will overwrite the file `token.cpp`.

### Step 3: Renew the Java source files
* The next step is to copy the arrays and numbers from `token.cpp` into `PerfectHash.java`. This should be obvious, if you look at the original versions of both files - they have a very similar structure.
* Finally, update the file `StyleConstants.java` with the integer values of the properties. Match the indexes of the corresponding words in the wordlist array in `PerfectHash.java`.
Fortunately, the list contains the indexes as comments.

(If you introduced new properties, add a corresponding entry to `StyleConstants.java`)

Example for the relation between `StyleConstants.java` and `PerfectHash.java`:

StyleConstants.java:

int STYLE_MARGIN_TOP = 6;

PerfectHash.java:

static String wordlist[] = { ...
"border-diagonal-color" /* hash value = 21, index = 7 */,
...


0 comments on commit cad3711

Please sign in to comment.