4 ms·
If you need to know if it's not empty, shoudn't it be easier to just test if the pointer to the first item is not-null ?
by fla 12y ago
If you need to know if it's not empty, shoudn't it be easier to just test if the pointer to the first item is not-null ?
- Betelgeuse90 12y agoDoes erlang have pointers?
- fla 12y agoI honestly don't know a thing about Erlang. But from my humble understanding of the interpreter source in the article: if is_list(list) is true, then the list is not empty. If you ask me, a respectable dequeue operation shoudn't need more than O(1).
- lostcolony 12y agoNo. In Erlang, is_list([]) is true. The correct implementation for checking if a list is empty would have been a pattern match, something akin to case List of [] -> empty; [_ | _] -> not_empty end. Or, you know. Reading the API docs and using queue:is_empty(Queue), which is O(1) instead of O(n) (which queue:len(Queue) is -explicitly stated to be-).