A Andrei E Member Licensed User Longtime User Mar 8, 2020 #1 How to properly fix this reverse function B4X: Sub Reverse(m As Map, p As String) For i = 0 To m.Size - 1 Dim k As Object = m.GetKeyAt(i) Dim v As Object = m.GetValueAt(i) If v Is Map Then Reverse(m.Get(k), "/" & k) Else Log(p & "/" & k) End If Next End Sub Usage example: B4X: Dim m As Map m.Initialize m.Put(1, "abc") m.Put(2, CreateMap(1 : "abc", 2 : "def")) m.Put(3, CreateMap(1 : "abc", 2 : "def", 3 : CreateMap(1 : "abc", 2: "def"))) Reverse(m, "") The result should be like this: /1 /2/1 /2/2 /3/1 /3/2 /3/3/1 /3/3/2 Click to expand... but it's incoorect /1 /2/1 /2/2 /3/1 /3/2 /3/1 /3/2 Click to expand...
How to properly fix this reverse function B4X: Sub Reverse(m As Map, p As String) For i = 0 To m.Size - 1 Dim k As Object = m.GetKeyAt(i) Dim v As Object = m.GetValueAt(i) If v Is Map Then Reverse(m.Get(k), "/" & k) Else Log(p & "/" & k) End If Next End Sub Usage example: B4X: Dim m As Map m.Initialize m.Put(1, "abc") m.Put(2, CreateMap(1 : "abc", 2 : "def")) m.Put(3, CreateMap(1 : "abc", 2 : "def", 3 : CreateMap(1 : "abc", 2: "def"))) Reverse(m, "") The result should be like this: /1 /2/1 /2/2 /3/1 /3/2 /3/3/1 /3/3/2 Click to expand... but it's incoorect /1 /2/1 /2/2 /3/1 /3/2 /3/1 /3/2 Click to expand...
Erel B4X founder Staff member Licensed User Longtime User Mar 8, 2020 #2 You should never use the deprecated GetKeyAt and GetValueAt. You should use B4XOrderedMap and sort the keys lexicographically. Upvote 0
You should never use the deprecated GetKeyAt and GetValueAt. You should use B4XOrderedMap and sort the keys lexicographically.
A Andrei E Member Licensed User Longtime User Mar 8, 2020 #3 Hi Erel I want to get proprly path (not a item sort) of map items Like a reverse search in the filesystem where the "Map" is a folder name and the filename is a string key of the map Upvote 0
Hi Erel I want to get proprly path (not a item sort) of map items Like a reverse search in the filesystem where the "Map" is a folder name and the filename is a string key of the map
Erel B4X founder Staff member Licensed User Longtime User Mar 8, 2020 #4 Use B4XOrderedMaps. It is very simple to go over the items in reverse order. Upvote 0