mirror of
https://github.com/rivo/tview.git
synced 2026-04-26 21:35:54 +03:00
[GH-ISSUE #88] code understanding for textview|Highlight using empty struct #68
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/tview#68
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @stephencheng on GitHub (Mar 28, 2018).
Original GitHub issue: https://github.com/rivo/tview/issues/88
I haven't had experience using the empty struct in go lang yet, though I understand there are a few benefits, I couldn't understand what purpose is to use the empty struct like below code.
The highlights is a map with id as key, but non value at all. Is it to achieve the goal of quick query if the id exist using the line like this?
if _, ok := t.highlights[regionID]; ok
@rivo commented on GitHub (Mar 28, 2018):
Correct. Go doesn't have built-in sets so a map with no values essentially turns it into a set. An empty struct uses no space so
map[string]struct{}is the most efficient (simple) way to do it.In line 583, I'm checking if a region is highlighted by querying the map.