puncsky
V2EX  ›  互联网

Geo-targeting 的 lookup table 如何设计数据结构?

  •  
  •   puncsky · Mar 20, 2015 · 2501 views
    This topic created in 4075 days ago, the information mentioned may be changed or developed.

    有些数据是随着地点变化的,比如广告的定价,那么如何设计存这种定价的数据结构呢?我猜是树形的,类似于 Trie

    对于 Location model:

    public class Location {
            // use fields as properties for simplicity.
            public String country;
            public String state;
            public String city;
        }
    

    使用三层的Trie:

    public class TrieNode {
            public BigDecimal price;
            public HashMap<String, TrieNode> edges = new HashMap<>();
        }
    

    好处就是,如果子节点不存在,父节点的价格可以覆盖子节点的价格。查找是 O(1) 的。

    求批评指正。

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2943 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 02:35 · PVG 10:35 · LAX 19:35 · JFK 22:35
    ♥ Do have faith in what you're doing.