分类 programming articles

Print Trick for Python

这是一个可以同时将print内容输出到屏幕以及保存到日志文件的简单代码。

主要利用了 builtins 对 print 方法进行 hook,从而让方法全局有效。

……

Continue reading

Crazy Import

最近发现 Django settings 在使用的时候,容易出现不经过检查的问题。 因此,想要在 settings 的基础上严格约束一下,减少问题。

……

Continue reading

在 MacOS 上使用 Ruby

Ruby 是一个伟大的编程语言,但是很多国内的工程师尚未体会到它的精髓。

MacOS 上本身自带一个 Ruby runtime,在笔者的系统上,这个版本是 2.6.0

……

Continue reading

# Difference between map & unordered_map

目前有三个容器我不太了解其内部实现,打算通过 <c++ primer> 进行学习 map multimap unordered_map map map 是目前最简单的结构,实现的方法是 BST(binary search tree)。因此,其时间复杂度等都与 BST 相同,搜索,增加,删除基本时间都是 log(n)。 use map when 数据有序 需要按照有序的顺序获得元素 unordered_map unordered_map 则是通常所说的 hash table,哈希表,搜索,增加,删除都是以hash表为主,较好的情况是o(1),也就是hash函数可以较好的把元素分布到表中,如果 hash 函数比较糟糕,则每一次添加删除查找,都是完整遍历一个表。 use unordered_map when 对数据计数 只需要根据 key 访问 value 简单来讲,就是当你需要使用 vector 来计数的时候,可以用 unordered_map 来代替。 multimap multimap containers are generally slower than unordered_multimap containers to access individual elements by their key, but they allow the direct iteration on subsets based on their order. Multimaps are typically implemented as binary search trees.……

Continue reading

Latest articles

Categories

Tags

Meta