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 求解 yolo算法问题
    • ¥15 虚拟机打包apk出现错误
    • ¥30 最小化遗憾贪心算法上界
    • ¥15 用visual studi code完成html页面
    • ¥15 聚类分析或者python进行数据分析
    • ¥15 逻辑谓词和消解原理的运用
    • ¥15 三菱伺服电机按启动按钮有使能但不动作
    • ¥15 js,页面2返回页面1时定位进入的设备
    • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
    • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。