News for hackers. Stuff that matters.
Re:Algorithms and Data Structures: Trie (Prefix tree) by bluefox on Wednesday November 09, 2016 @09:40PM (#12917254)
Yes. Another simple representation if you assume a maximum number of occurrences per letter:

  (defvar *alphabet* "abcdefghijklmnopqrstuvwxyz")
  
  (defconstant capacity-in-bits 3)
  
  (defun key (word)
    (loop with key = 0
          with max-occurrences = (1- (ash 1 capacity-in-bits))
          for letter across *alphabet*
          for i upfrom 0
          for occurrences = (count letter word)
          do (if (> occurrences max-occurrences)
                 (error "too many occurrences")
                 (setf (ldb (byte capacity-in-bits (* i capacity-in-bits)) key)
                       occurrences))
          finally (return key)))

There are no comments on this comment yet.