1+ using DoubleArrayTries: StringView
2+
13struct Merge
24 string:: String
35 offset:: UInt16
46 ncodeunits:: UInt16
57 extra:: Bool
8+ byte:: Bool
69end
710
8- Merge (str, offset:: Int , ncodeunits:: Int , extra) = Merge (str, UInt16 (offset), UInt16 (ncodeunits), extra)
9- Merge (a:: Merge , e:: Bool ) = Merge (a. string, a. offset, a. ncodeunits, e)
10- Merge (s:: SubString , e:: Bool = false ) = Merge (s. string, s. offset, s. ncodeunits, e)
11+ Merge (str, offset:: Int , ncodeunits:: Int , extra, byte = false ) = Merge (str, UInt16 (offset), UInt16 (ncodeunits), extra, byte )
12+ Merge (a:: Merge , e:: Bool ) = Merge (a. string, a. offset, a. ncodeunits, e, a . byte )
13+ Merge (s:: SubString , e:: Bool = false ) = Merge (s. string, s. offset, s. ncodeunits, e, false )
1114Merge (s:: String , e:: Bool = false ) = Merge (SubString (s), e)
1215
1316function Merge (a:: Merge , b:: Merge )
@@ -22,7 +25,7 @@ function Merge(a::Merge, b::Merge)
2225 error (" merge two Merge at same offset: partial string?" )
2326 end
2427 nunits = a. ncodeunits + b. ncodeunits
25- return Merge (a. string, offset, nunits, b. extra)
28+ return Merge (a. string, offset, nunits, b. extra, a . byte & b . byte )
2629 else
2730 error (" merge different Merge" )
2831 end
@@ -92,7 +95,7 @@ function write_merges(io::IO, rank, endsym = nothing; limit = typemax(Int), comm
9295end
9396
9497function Base. hash (m:: Merge , h:: UInt )
95- h = hash (m. extra, h) + Base. memhash_seed
98+ h = hash (m. byte, hash (m . extra, h) ) + Base. memhash_seed
9699 str_size = m. ncodeunits * sizeof (UInt8)
97100 str = m. string
98101 ptr = convert (Ptr{UInt8}, pointer (str)) + m. offset
@@ -103,6 +106,7 @@ function Base.:(==)(m1::Merge, m2::Merge)
103106 m1. extra == m2. extra || return false
104107 s = m1. ncodeunits
105108 s == m2. ncodeunits || return false
109+ m1. byte == m2. byte || return false
106110 str1 = m1. string
107111 str2 = m2. string
108112 p1 = convert (Ptr{UInt8}, pointer (str1)) + m1. offset
113117function as_string (m:: Merge , sepsym, endsym)
114118 str = m. string
115119 offset = m. offset
116- s = SubString (str, offset+ 1 , prevind (str, offset + m. ncodeunits + 1 ))
120+ cu = codeunits (str)
121+ range = offset+ 1 : offset+ m. ncodeunits
122+ if m. byte
123+ s = join ((" <0x$(uppercase (string (cu[i]; base= 16 , pad= 2 ))) >" for i in range))
124+ else
125+ s = StringView (@view (cu[range]))
126+ end
117127 sym = m. extra ? endsym : sepsym
118128 return isnothing (sym) ? String (s) : string (s, sym)
119129end
0 commit comments