doujian3132 2018-03-06 16:22
浏览 7

查找具有与字符串数组匹配的值的地图项?

I have my code working but I am sure that it is not optimal.

I am building a Map[string]string that contains my alarm names as keys and instanceids as values. I have an array that has just instanceids in it. I need to remove any keys from the map that have values that match the instanceids in the array. Then return a []string of alarm names. My code is working but thought that it would be good to see if I did this remotely correct. The []string in the return is optional I could probably just use the map.

Thanks for the input.

func CheckAlarms(alarmMap map[string]string, instances []string) (result []string)  {

    var AlarmList []string

    for _, inst := range instances{

        for k, v := range alarmMap{

            if v == inst{
                log.Printf("**** Match Found add alarm to delete list %s
", k)
                delete(alarmMap, k)
            }
        }

    }

    for k, v := range alarmMap{
        var inst []string


        AlarmList = append(AlarmList, k)
        inst = append(inst, v)

    }

    log.Printf("end of function list length %d", len(AlarmList))
return AlarmList
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 eclipse开启服务后,网页无法打开
    • ¥30 雷达辐射源信号参考模型
    • ¥15 html+css+js如何实现这样子的效果?
    • ¥15 STM32单片机自主设计
    • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
    • ¥15 不小心不正规的开发公司导致不给我们y码,
    • ¥15 我的代码无法在vc++中运行呀,错误很多
    • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
    • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
    • ¥30 ppOCRLabel导出识别结果失败