Skip to content

Minor algorithmic improvements.#5

Open
ruricolist wants to merge 4 commits into
MatthewRock:masterfrom
ruricolist:master
Open

Minor algorithmic improvements.#5
ruricolist wants to merge 4 commits into
MatthewRock:masterfrom
ruricolist:master

Conversation

@ruricolist

Copy link
Copy Markdown

This avoids using concatenate to build up strings, and avoids using sort to insert new items into the list of children.

@MatthewRock MatthewRock left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your work! I've found some time to review the changes. My code leave a lot of room for improvement, so thanks for bearing with me. The changes look good; the only thing I would ask for is to add some comments; the code requires you to stop and think for a minute.

Comment thread src/trie.lisp
(when k (string k)))
""))))
(type list prefix))
(let ((new-prefix

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add some comments to make it easier to glance over this code.

Comment thread src/trie.lisp
(recursive-fun trie ""))
(let* ((len (reduce #'+ new-prefix :key #'length))
(string (make-string len)))
(loop for p in new-prefix

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively we can move this let and loop into a FLET function, e.g. "prefix-to-key" (though I don't really like this name... throwing out the idea though)

Comment thread src/trie.lisp
(list new-node (sort (cons new-node children-list)
#'char-greaterp :key #'key)))))
(values new-node
(if (null children-list)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment to explain this operation (or better yet, create a named local function for this purpose).

Comment thread src/package.lisp
;; Conditions
empty-key-warning
wrong-key-type-error))
#:empty-key-warning

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious - what are the practical implications of this? What are we gaining by not interning the symbols?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way I see it is that avoiding interning symbols is just polite: interned symbols are never garbage-collected, they result in noise when you call apropos, and they can result in needless package conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants