new new
This commit is contained in:
+49
-7
@@ -1,7 +1,7 @@
|
||||
package playlist
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
"errors"
|
||||
"strconv"
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"../config"
|
||||
)
|
||||
|
||||
var pln = fmt.Println
|
||||
var pln = log.Println
|
||||
|
||||
type Playlist struct {
|
||||
NAME string
|
||||
@@ -105,6 +105,14 @@ func (pp *PrettyPlaylist) Print() {
|
||||
}
|
||||
}
|
||||
|
||||
func print(slice []uint32) {
|
||||
for i, r := range slice {
|
||||
pln(" " + strconv.Itoa(i) + " - " + archive.Archive_map[r].NAME)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// https://github.com/golang/go/wiki/SliceTricks
|
||||
// https://stackoverflow.com/questions/33834742/remove-and-adding-elements-to-array-in-go-lang
|
||||
|
||||
func (p *Playlist) Pop() error {
|
||||
@@ -157,20 +165,54 @@ func (p *Playlist) Insert(track_id uint32, at_index int) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Playlist) Delete(track_id uint32) error {
|
||||
|
||||
func (p *Playlist) index(track_id uint32) int {
|
||||
k := -1
|
||||
for i := 0; i <= len(p.LIST); i++ {
|
||||
for i := 0; i < len(p.LIST); i++ {
|
||||
if p.LIST[i] == track_id { k = i }
|
||||
}
|
||||
return k
|
||||
}
|
||||
|
||||
func (p *Playlist) Delete(track_id uint32) error {
|
||||
k := p.index(track_id);
|
||||
if k < 0 {
|
||||
return errors.New("Invalid track ID")
|
||||
}
|
||||
p.LIST = append(p.LIST[:k-1], p.LIST[k+1:]...)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Playlist) Move(track_id uint32, at_index int) error {
|
||||
if at_index > p.MAX {
|
||||
return errors.New("Invalid insert index")
|
||||
}
|
||||
k := p.index(track_id);
|
||||
if k < 0 {
|
||||
return errors.New("Invalid track ID")
|
||||
}
|
||||
|
||||
p.LIST = append(p.LIST[:k-1], p.LIST[k+1:]...)
|
||||
return nil
|
||||
slice_head := p.LIST[:k]
|
||||
slice_move := p.LIST[k+1:at_index+1]
|
||||
slice_tail := make([]uint32, len(p.LIST[at_index+1:]))
|
||||
copy(slice_tail, p.LIST[at_index+1:])
|
||||
|
||||
// slice_move = append(slice_move, track_id)
|
||||
|
||||
pln("from_index: " + strconv.Itoa(k))
|
||||
pln("at_index: " + strconv.Itoa(at_index))
|
||||
pln("------")
|
||||
pln("slice head: ")
|
||||
print(slice_head)
|
||||
pln("slice move: ")
|
||||
print(slice_move)
|
||||
pln("** ")
|
||||
pln("slice tail: ")
|
||||
print(slice_tail)
|
||||
pln("...........................")
|
||||
|
||||
p.LIST = append(slice_head, append(append(slice_move, track_id), slice_tail...)...)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user