Repository navigation
MapPage
SkipListMap is a scalable SortedMap implementation based on a skip list. The elements are ordered according to the specific parameter 'precede'. This collection implements all operations of SortedMap like add and remove.
The initialization of SkipListMap is a bit complicated because it may contain two or more different types of elements. In the following case, the type of key is Teacher, the type of value is the Collection, and the elements in each collection are of Student type.
var precede = func(p1 *collection.Object, p2 *collection.Object) bool {
s1 := (*p1).(Teacher)
s2 := (*p2).(Teacher)
return s1.Id < s2.Id
}
var t2 collection.Object = Teacher{2, "t2", 0}
var t4 collection.Object = Teacher{4, "t4", 0}
var t6 collection.Object = Teacher{6, "t6", 0}
var t8 collection.Object = Teacher{8, "t8", 0}
var st11 collection.Object = Student{100, "st11"}
var st12 collection.Object = Student{101, "st12"}
var st2 collection.Object = Student{102, "st2"}
var st3 collection.Object = Student{103, "st3"}
var st4 collection.Object = Student{104, "st4"}
var s1 collection.Object = *hashset.New()
var s2 collection.Object = *hashset.New()
var s3 collection.Object = *hashset.New()
var s4 collection.Object = *hashset.New()
s1s := s1.(hashset.HashSet)
s2s := s2.(hashset.HashSet)
s3s := s3.(hashset.HashSet)
s4s := s4.(hashset.HashSet)
s1s.Add(&st11)
s1s.Add(&st12)
s2s.Add(&st2)
s3s.Add(&st3)
s4s.Add(&st4)
var m = skiplistmap.New(precede)
m.Put(&t2, &s1)
m.Put(&t4, &s2)
m.Put(&t6, &s3)
m.Put(&t8, &s4)After that, we can use the useful methods inside, such as put (to add elements) and get (to get elements).
var t5 collection.Object = Teacher{5, "t5", 0}
var st5 collection.Object = Student{102, "st2"}
s5 := *hashset.New()
s5.Add(&st5)
var s5o collection.Object = s5
m.Put(&t5, &s5o)
m.Get(&t5)Navigation methods returning the closest matches for given search targets are included in this sorted collection.
var temp1 collection.Object = Teacher{1, "t1", 0}
k1 := m.FloorEntry(&temp1)Submaps returned by SkipListMap submap operations represent a subrange of mappings of their underlying maps. Instances of this class support all methods of their underlying maps, differing in that mappings or attempting to add mappings outside their range are ignored. Instances of this class are constructed only using the subMap, headMap, and tailMap methods of their underlying maps.
var _ = m.SubMap(nil, false, nil, false)
var _ = m.TailMap(&t4, true)
var _ = m.HeadMap(&t2, true)EntrySet is a Set view of the mappings contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. KeySet a SortedSet view of the keys contained in this map, and Values is a Collection view of the values contained in this map.
var _ = m.EntrySet()
var _ = m.KeySet()
var _ = m.Values()