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