你好,我对c ++和openframeworks有点新意,我试图通过从矢量中移出屏幕后的元素来让我的程序运行得更顺畅。随着时间的推移,它仍然变得越来越慢。我突然对此不以为然。如果你知道如何改进这个。
// extract all the "itm_id" values from all dictionaries in the array
// use a set to identify unique values
// map each unique values to its count in the array
let ids = dictionaries.flatMap{$0["itm_id"] as? Int}
let idCounts = Set(ids).map{ id in (id, ids.filter{$0==id}.count) }
// You can use map() to turn this into yet another array of dictionaries
let idCountDict = idCounts.map{["itm_id":$0 ,"count":$1]}
print(idCounts) // [(4, 3), (7, 1)]
print(idCountDict) // [["itm_id": 4, "count": 3], ["itm_id": 7, "count": 1]]