Fresh IDE . Check-in [2921f201b0]
Not logged in

This repository is a mirror!

The original is located on: https://fresh.flatassembler.net/fossil/repo/fresh
If you want to follow the project, please update your remote-url

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Added the macro library _minihash.asm for creating static hash tables based on Pearsons hash function. Added test project for buffergap.asm library (TText buffers).
Timelines: family | ancestors | descendants | both | FreshLibDev
Files: files | file ages | folders
SHA1:2921f201b039c71059586ca82e09ec9269448bcb
User & Date: johnfound 2018-09-29 18:28:50
Context
2018-09-29
18:31
Wrong file extension fixed. check-in: 8a79ae04a3 user: johnfound tags: FreshLibDev
18:28
Added the macro library _minihash.asm for creating static hash tables based on Pearsons hash function. Added test project for buffergap.asm library (TText buffers). check-in: 2921f201b0 user: johnfound tags: FreshLibDev
2018-09-23
12:12
Cosmetics. check-in: 099acdad4d user: johnfound tags: FreshLibDev
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added freshlib/macros/_minihash.asm.



























































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
; Pearsons hash function table:

struct TPHashItem
  .pKeyname    dd ?     ; pointer to the key name. on [.pKeyname-1] is 1 byte key length.
  .Value       dd ?     ; user defined value of the hash table cell.
ends

;
; Builds static Pearsons hash table.
; The table contains 256 elements of TPHashItem (in total 2048 bytes)
;
; Arguments:
;   table - the lable of the hash table.
;   Pfunc - table of 256 random (or not random) bytes - values of the Pearsons hash function.
;   key   - string that to be hashed. Pointer to this string is placed in the .pKeyname field of
;           the respective record of the hash table. The hash of the key is computed case insensitive.
;   value - user data. Placed in the .Value field of the respective TPHashItem element.
;
; Notice, that the table does not resolve hash collisions. If collision happens, the compilation ends
; with error. The conflict can be resolved in two ways - changing the hash function in order to
; avoid collisions, or changing the key that causes collision.
;
macro PHashTable table, Pfunc, [key, value] {
common
if used table
  local ..error
  ..error = 0

  if defined options.ShowHashes & options.ShowHashes
    disp 3, 'Hash table "', `table, '"', 9
  end if

  table dd 256 dup(0,0)

forward
local ..keynm, ..len, ..hash, ..char, ..prev

          db ..len
  ..keynm db key
  ..len = $ - ..keynm
         db 0

  if value
    ..hash = 0
    repeat ..len
      load ..char byte from ..keynm + % - 1
      if ..char and $40
        ..char = ..char or $20
      end if
      ..hash = ..hash xor ..char
      load ..hash byte from Pfunc + ..hash
    end repeat

    if defined options.ShowHashes & options.ShowHashes
      disp 3,'Keyword hash : ', <..hash, 10>, ' on "', key, '"', 10
    end if

    load ..prev dword from table + ..hash * 8

    if ..prev = 0
      store dword ..keynm at table + ..hash * 8
      store dword value at table + ..hash * 8 + 4
    else
      disp 2,'Hash collision: ', <..hash, 10>, ' on "', key, '"', 10
      ..error = 1
    end if
  end if

common
  if defined options.ShowHashes & options.ShowHashes
    disp 6, '---', 13
  end if
  assert ~..error

  end if
}

;
; Computes the Pearsons hash in the same way as PHashTable macro.
; Useful for defining constants with the hash value of some key.
;
; usage:
;   MyHashConst phash PFUNK, "my_string"
;
struc phash Pfunc, key {
local ..keynm, ..len, ..hash, ..char

  virtual at 0
    ..keynm::
      db key
    ..len = $
  end virtual

  ..hash = 0
  repeat ..len
    load ..char byte from ..keynm:(% - 1)
    if ..char and $40
      ..char = ..char or $20
    end if
    ..hash = ..hash xor ..char
    load ..hash byte from Pfunc + ..hash
  end repeat

  if defined options.ShowHashes & options.ShowHashes
    disp 3,'Keyword hash : ', <..hash, 10>, ' on "', key, '"', 10
  end if

  . = ..hash
}

Changes to freshlib/macros/allmacros.inc.

18
19
20
21
22
23
24

25
26
include '_struct.inc'
include '_display.inc'
include '_itext.inc'
include '_globals.inc'
include '_datamacros.inc'
include '_dispatch.inc'
include '_realobjects.inc'


include '%TargetOS%/allmacros.inc'







>


18
19
20
21
22
23
24
25
26
27
include '_struct.inc'
include '_display.inc'
include '_itext.inc'
include '_globals.inc'
include '_datamacros.inc'
include '_dispatch.inc'
include '_realobjects.inc'
include '_minihash.inc'

include '%TargetOS%/allmacros.inc'

Added freshlib/test_code/TestGapBuffers.asm.

































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
; _______________________________________________________________________________________
;|                                                                                       |
;| ..:: Fresh IDE ::..  template project.                                                |
;|_______________________________________________________________________________________|
;
;  Description: FreshLib portable console application.
;
;  Target OS: Any, supported by FreshLib
;
;  Dependencies: FreshLib
;
;  Notes:
;_________________________________________________________________________________________

include "%lib%/freshlib.inc"

@BinaryType console, compact

include "%lib%/freshlib.asm"

; include your includes here.

start:
        InitializeAll

        stdcall TextCreate, sizeof.TText
        mov     edx, eax

        stdcall TextAddString, edx, 0, "This is test"
        stdcall TextAddString, edx, 8, "simply a small, simple but reliable "

        stdcall TextMoveGap, edx, -100000
        stdcall TextMoveGap, edx, +100000

        stdcall TextMoveGap, edx, 4
        sub     [edx+TText.GapBegin], 4

        stdcall TextAddString, edx, 0, txt "Katakana"

        stdcall TextMoveGap, edx, -1
        sub     [edx+TText.GapBegin], 4

        stdcall TextAddString, edx, [edx+TText.GapBegin], "alphabet."

;        int3
        stdcall TextCompact, edx

        push    eax

        stdcall FileWrite, [STDERR], edx, eax
        stdcall FileWriteString, [STDERR], <txt "<<<<<<<", 13, 10, "Text length: ">

        pop     eax
        stdcall NumToStr, eax, ntsDec or ntsUnsigned

        stdcall FileWriteString, [STDERR], eax
        stdcall FileWriteString, [STDERR], <txt 13, 10>

        stdcall NumToStr, [edx+TText.GapEnd], ntsDec
        push    eax

        stdcall NumToStr, [edx+TText.GapBegin], ntsDec
        push    eax

        stdcall NumToStr, [edx+TText.Length], ntsDec
        push    eax

        stdcall FileWriteString, [STDERR], "TText length: "
        stdcall FileWriteString, [STDERR] ; from the stack

        stdcall FileWriteString, [STDERR], <txt 13, 10, "Gap begin: ">
        stdcall FileWriteString, [STDERR] ; from the stack

        stdcall FileWriteString, [STDERR], <txt 13, 10, "Gap end: ">
        stdcall FileWriteString, [STDERR] ; from the stack

        stdcall FileWriteString, [STDERR], <txt 13, 10>

        FinalizeAll
        stdcall TerminateAll, 0

Added freshlib/test_code/TestGapBuffers.fpr.

cannot compute difference between binary files