Re: [go-nuts] Character Replacement/Algorithm for Replacement

2018-08-30 Thread Michael Jones
Always true. But hard to believe that a map could be faster. The array will be on the stack. On Thu, Aug 30, 2018 at 9:31 AM Marvin Renich wrote: > * Michael Jones [180830 11:44]: > > The task to "translate a string through a table" is common. It is a > single > > computer instruction (TR) in t

Re: [go-nuts] Character Replacement/Algorithm for Replacement

2018-08-30 Thread Marvin Renich
* Michael Jones [180830 11:44]: > The task to "translate a string through a table" is common. It is a single > computer instruction (TR) in the IBM 360 and was extended over time with > related instructions for conversion in and out of UTF-8, testing before and > after translation, and expanded ch

Re: [go-nuts] Character Replacement/Algorithm for Replacement

2018-08-30 Thread Michael Jones
The task to "translate a string through a table" is common. It is a single computer instruction (TR) in the IBM 360 and was extended over time with related instructions for conversion in and out of UTF-8, testing before and after translation, and expanded character sizes. Tamás Gulácsi's approach w

Re: [go-nuts] Character Replacement/Algorithm for Replacement

2018-08-30 Thread Marvin Renich
* Tamás Gulácsi [180830 01:17]: > An even faster lookup is creating a [256]byte array for the replacements, > having the 9 replacements candidates _position_ having the replacements, > all others the identity: > > // prepare the lookup table > var a [256]byte > for i := 0; i<256; i++ { > a[i]

Re: [go-nuts] Character Replacement/Algorithm for Replacement

2018-08-29 Thread Tamás Gulácsi
An even faster lookup is creating a [256]byte array for the replacements, having the 9 replacements candidates _position_ having the replacements, all others the identity: // prepare the lookup table var a [256]byte for i := 0; i<256; i++ { a[i] = i } a[37] = '-' a[129] = '-' ... // replace t

Re: [go-nuts] Character Replacement/Algorithm for Replacement

2018-08-29 Thread agruetz45
Makes sense. Best I am going to get is a linear search w/ a divide and conquer if I want to speed it up. Thanks needed the sounding board and feed back. Thanks, Anthony On Wednesday, August 29, 2018 at 8:16:44 PM UTC-7, Daniela Petruzalek wrote: > > Do you have an example? > > I'm assuming tha

Re: [go-nuts] Character Replacement/Algorithm for Replacement

2018-08-29 Thread Daniela Petruzalek
Do you have an example? I'm assuming that the replacement is one character for another. (ie.: not one character being replaced by a group of characters). Regarding to finding the positions to replace you can't beat O(n) complexity as you must look at least once at every character on the source st

[go-nuts] Character Replacement/Algorithm for Replacement

2018-08-29 Thread agruetz45
I have approximately 9 characters that all need to be replaced with different characters. I know there are a number of ways to do this but what is the most efficient? - 1) Do a []byte walk and compare each byte and replace when found? - Seems expensive if you have a 100 bytes in the []byt