I just released a package called intern <https://github.com/spakin/intern> 
for speeding up string comparisons.  Install it in the usual manner:

go get github.com/spakin/intern


The package defines two interned-string types, Eq and LGE, and functions to 
allocate them.  Internally, both are represented as integers so comparisons 
run in constant time, regardless of the length of the corresponding string. 
 Hence, programs that frequently compare strings, especially strings with 
large, common prefixes, stand to gain the most in performance.

Both Eq and LGE define a String method that recovers the original string. 
 Hence, in some cases (e.g., fmt.Printf <https://golang.org/pkg/fmt/#Printf>) 
they can serve as a drop-in replacement for strings.

The difference between the two types is the set of comparisons they 
support.  For strings s1 and s2 and corresponding Eqs e1 and e2,

   - if s1 == s2 then e1 == e2, and
   - If s1 != s2 then e1 != e2.

LGEs, which I've never encountered in a string-interning package for *any* 
language, support a richer set of comparisons.  For strings s1 and s2 and 
corresponding LGEs l1 and l2,

   - if s1 == s2 then l1 == l2,
   - if s1 != s2 then l1 != l2,
   - if s1 < s2 then l1 < l2,
   - if s1 > s2 then l1 > l2,
   - and likewise for <= and >=.

However, LGEs are slower to allocate than Eqs, and allocation can fail. 
 See the package documentation <https://godoc.org/github.com/spakin/intern> and 
examples for information on how to recover from that situation.

Enjoy,
— Scott

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to