Reg iterating key value in Map

Hi Team,
I am getting below result while using Map

map: map[17:1]
map: map[8191:6]
map: map[8191:7]
map: map[8191:7]
map: map[17:2]

I need to split 8191 key values separately and 17 key values separately from Map as below

Results for 8191- 6,7,7 and 17-1,2.

How to achieve this?

Thanks,
Raja

Sorry, but I do not really understand your requirements.

Could you please write a small program on the playground which shows your input data and how you want to process it or at least how the expected data should look like (in go syntax)?

My requirement -I need to get ContinuityCounter values from video based on pid(packet identifier) and Validated pid has proper ContinuityCounter values.

		m := make(map[uint16]uint8)
		m[pid] = cc
		fmt.Println("map:", m)

Above code pid will return 8191,17 values and cc(ContinuityCounter) will return 1,6,7,7 values.So i have created map to find ContinuityCounter based on pid which will retrun below results.
map: map[17:1]
map: map[8191:6]
map: map[8191:7]
map: map[8191:7]
map: map[17:2]

from that i need to split cc values based on pid. Since code is huge , I couldn’t post.

Thanks,
Raja

In your code nothing is returned, but printed only.

Also since you only showed a single snippet which only initialises the map with a single KV-pair and printing it once, I have to assume, that on each iteration the previous map is lost.

Based on this assumptions you can not do anything with the history.

Start with actually implementing a proper history.

Still I do not really get what you want.

Therefore I ask again, if you can show in a proper playground what your input is, and what your expected output is.

And again, please use proper go code to describe your actual and expected data, not some pseudo-debug output that doesn’t tell anything.

ok.I will create some data and post.

Thanks,
Raja

Please correct me if I am wrong.
You need something like this in the end
So, you need to store the values in the slice previously LIKE
https://play.golang.org/p/0h9NE2PVt3b

Thanks,

I have created sample code below
https://play.golang.org/p/ln2lhcDQC24

From this i need to split key 8191 and 17 values separately and need to find difference between its values
For Example
map: map[8191:0]
map: map[8191:1]
map: map[8191:2]
map: map[8191:2]

map: map[17:1]
map: map[17:2]
map: map[17:7]
map: map[17:9]

i need to get all the 8191 key and find difference between value 0 and 1(Result 1) and 2 and 2 difference (Result 0).same i have to do for 17 as well.

Hi

I think it would be better to store the values as

map[uint16][]uint8

Then you can easily look up 17 and 8191 and get corrext values

https://play.golang.org/p/XKt_JSpC08g

package main

import (
	"fmt"
)

func main() {
	m := make(map[uint16][]uint8)
	
	m[17] = append(m[17], 1)
	
	m[8191] = append(m[8191], 6)
	m[8191] = append(m[8191], 7)
	m[8191] = append(m[8191], 7)
	m[17] = append(m[17], 2)
		
	fmt.Println(m)
	
	fmt.Println(m[17])
	fmt.Println(m[8191])
}

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.