linkedin_38771105 2017-05-13 05:44
浏览 638

一个Adobe 的面试题!!!!!

Let's write a new class called int_map which:

1 Is an associative map of int -> int

2 Has a size specified at construction, and all mappings from 0 to size-1 initialized to the same specified value

3 Supports get/set of individual mappings

Let's keep the interface simple:

class int_map

{

... member variables ...

public:

int_map(int num_values, int initial_val);



int get(int index) const;



void set(int index, int value);

};

Problem 1: Write this class using a std::vector.

Problem 2:

Let's suppose we expect the mapping to contain long spans of identical values, and that run-length encoding the map will yield good storage gains:

class rle_int_map

{

struct run

{

    int m_stop;

    int m_value;

};



// The first run implicitly starts at 0; all subsequent runs start at the previous run's m_stop

std::vector<run> m_runs;

public:

rle_int_map(int num_values, int initial_val)

{

    m_runs.push_back({ num_values, initial_val });

}



int get(int index) const

{

    // It is illegal to pass in an invalid index, for the purposes of this exercise we can

    // just assert()

    assert(0 <= index && index < m_runs.back().m_stop);



    for (auto const& r : m_runs)

    {

        if (r.m_stop > index)

            return r.m_value;

    }

    assert(false); // Shouldn't get here

}



void set(int index, int value)

{

    ???

}

};

Can you write a more efficient version of rle_int_map::get()?

Problem 3: Provide a correct implementation of rle_int_map::set().

请问第二问第三问什么意思? rle map 是个什么意思 求解释 那个run struct到底是做什么的?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 c程序不知道为什么得不到结果
    • ¥40 复杂的限制性的商函数处理
    • ¥15 程序不包含适用于入口点的静态Main方法
    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置