什么时候应该使用BitVector32? [英] When should I use a BitVector32?

查看:201
本文介绍了什么时候应该使用BitVector32?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个项目,在某个时刻我需要显示一个月的时间,这些天仍然可用.有一个功能可以计算哪些日期可用.我的同事说:哦,我们知道,您应该返回 BitVector32 .这是处理布尔列表时最有效的方法."我会使用 List<bool> 或类似的东西. BitVector32 在您实际使用位时,对我来说似乎是一些低级的东西.

I am working on a project where at a certain moment I need to show for one month which days are still available. There is a function that calculates which days are available. My colleagues said:"Oh we know, you should return a BitVector32. That's the most efficient when working with a list of booleans." I would have used a List<bool> or something like that. A BitVector32 seems to me to be something for low level stuff when you are actually working with bits.

所以,问题是.您是否应该使用 BitVector32 每当需要少于32个项目的布尔值列表时,还是只应将其用于低级内容?

So, the question is. Should you use the BitVector32 whenever you need some list of booleans with less than 32 items or should you only use it for low level stuff?

推荐答案

使用列表很容易扩展到其他时间段.假设您要一次显示两个月.哦,它大于32.我需要更改返回类型及其使用的所有位置.伟大的!而且BitVector32甚至没有实现IEnumerable<T>.

Using a List is easily extensible to other time periods. Say you want to show two month at once. Oh that's bigger than 32. I need to change the return type and everywhere it's used. Great! And BitVector32 doesn't even implement IEnumerable<T>.

并且除非处于紧密的循环中,否则可读性和可维护性都是最高效率.而且,除非您每秒执行一百万次,否则列表分配的开销不会太大.

And unless it's in a tight loop readability and maintainability top efficiency. And the overhead of a list allocation isn't that big, unless you do it a million times per second.

因此,我同意您的意见,只应将BitVector32用于低级代码.

So I agree with you that you should only use BitVector32 for low level code.

这篇关于什么时候应该使用BitVector32?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆