item -> Item

This commit is contained in:
geek 2017-04-26 16:48:49 +09:00
parent 50f80fb220
commit bf078e46ed
3 changed files with 30 additions and 14 deletions

View File

@ -0,0 +1,10 @@
<component name="libraryTable">
<library name="Go SDK">
<CLASSES>
<root url="file://$PROJECT_DIR$/../../../../../1.8/src" />
</CLASSES>
<SOURCES>
<root url="file://$PROJECT_DIR$/../../../../../1.8/src" />
</SOURCES>
</library>
</component>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -14,13 +14,13 @@ const (
EVENT_TYPE EventType = 1
)
type item struct {
value interface{}
priority int
type Item struct {
Value interface{}
Priority int
}
type LoafleQueue struct {
items []*item
items []*Item
queueType string
interval time.Duration
@ -33,19 +33,19 @@ func (lq LoafleQueue) Len() int {
func (lq LoafleQueue) Less(i, j int) bool {
return lq.items[i].priority < lq.items[j].priority
return lq.items[i].Priority < lq.items[j].Priority
}
func (lq LoafleQueue) Swap(i, j int) {
lq.items[i], lq.items[j] = lq.items[j], lq.items[i]
}
func (lq *LoafleQueue) GetItems() []*item {
func (lq *LoafleQueue) GetItems() []*Item {
time.Sleep(time.Second * lq.interval)
resultItems := make([]*item, 0)
resultItems := make([]*Item, 0)
for lq.Len() > 0 {
item := heap.Pop(lq).(*item)
item := heap.Pop(lq).(*Item)
resultItems = append(resultItems, item)
}
return resultItems
@ -53,8 +53,8 @@ func (lq *LoafleQueue) GetItems() []*item {
func (lq *LoafleQueue) Push(i interface{}) {
n := len(lq.items)
nItem := i.(*item)
nItem.priority = n
nItem := i.(*Item)
nItem.Priority = n
lq.items = append(lq.items, nItem)
}
@ -65,9 +65,9 @@ func (lq *LoafleQueue) Pop() interface{} {
lq.items = old[0 : n-1]
return nItem
}
func (lq LoafleQueue) newItem(value interface{}) *item {
return &item{
value: value,
func (lq LoafleQueue) newItem(value interface{}) *Item {
return &Item{
Value: value,
}
}
@ -98,7 +98,7 @@ func (lq *LoafleQueue) Close() {
}
}
func NewQueue(eventType EventType, interval time.Duration) *LoafleQueue {
items := make([]*item, 0)
items := make([]*Item, 0)
event := make(chan interface{}, 0)
lq := &LoafleQueue{