q*e
2 楼
【 以下文字转载自 Medicine 讨论区 】
发信人: queque (queque), 信区: Medicine
标 题: 请问哪一款电动牙刷比较好?谢谢,不知道有没有发错版
发信站: BBS 未名空间站 (Sun Oct 23 20:10:15 2011, 美东)
请教一下哪一款电动牙刷大家觉得比较好用,能刷的比较干净。常见的就是oral-b和Philips Sonicare,不知道哪一个型号的最好。多谢推荐,谢谢!要是
发错版面的话,请问应该到哪个版去问?
发信人: queque (queque), 信区: Medicine
标 题: 请问哪一款电动牙刷比较好?谢谢,不知道有没有发错版
发信站: BBS 未名空间站 (Sun Oct 23 20:10:15 2011, 美东)
请教一下哪一款电动牙刷大家觉得比较好用,能刷的比较干净。常见的就是oral-b和Philips Sonicare,不知道哪一个型号的最好。多谢推荐,谢谢!要是
发错版面的话,请问应该到哪个版去问?
s*n
3 楼
就是写两个overload吧?
COWString& operator=(const char*)
COWString& operator=(const COWString&)
COWString& operator=(const char*)
COWString& operator=(const COWString&)
e*t
4 楼
只用过sonicare,还没有理由换它。
Philips Sonicare,不知道哪一个型号的最好。多谢推荐,谢谢!要是
【在 q****e 的大作中提到】
: 【 以下文字转载自 Medicine 讨论区 】
: 发信人: queque (queque), 信区: Medicine
: 标 题: 请问哪一款电动牙刷比较好?谢谢,不知道有没有发错版
: 发信站: BBS 未名空间站 (Sun Oct 23 20:10:15 2011, 美东)
: 请教一下哪一款电动牙刷大家觉得比较好用,能刷的比较干净。常见的就是oral-b和Philips Sonicare,不知道哪一个型号的最好。多谢推荐,谢谢!要是
: 发错版面的话,请问应该到哪个版去问?
Philips Sonicare,不知道哪一个型号的最好。多谢推荐,谢谢!要是
【在 q****e 的大作中提到】
: 【 以下文字转载自 Medicine 讨论区 】
: 发信人: queque (queque), 信区: Medicine
: 标 题: 请问哪一款电动牙刷比较好?谢谢,不知道有没有发错版
: 发信站: BBS 未名空间站 (Sun Oct 23 20:10:15 2011, 美东)
: 请教一下哪一款电动牙刷大家觉得比较好用,能刷的比较干净。常见的就是oral-b和Philips Sonicare,不知道哪一个型号的最好。多谢推荐,谢谢!要是
: 发错版面的话,请问应该到哪个版去问?
q*c
5 楼
什么叫copy on write? 不懂这个,那一电面不歇菜了? 不是说F止考算法和数据结构吗
?
?
r*b
7 楼
I think that it is more complex that this. We need to consider both updating
the whole string, and updating one character in the string.
Here is what I thought about the implementation:
http://basicalgos.blogspot.com/2012/03/16-implement-copy-on-wri
【在 s******n 的大作中提到】
: 就是写两个overload吧?
: COWString& operator=(const char*)
: COWString& operator=(const COWString&)
the whole string, and updating one character in the string.
Here is what I thought about the implementation:
http://basicalgos.blogspot.com/2012/03/16-implement-copy-on-wri
【在 s******n 的大作中提到】
: 就是写两个overload吧?
: COWString& operator=(const char*)
: COWString& operator=(const COWString&)
S*y
9 楼
Re
p*2
11 楼
不懂呀。
k*o
12 楼
Philips Sonicare的,洗牙牙医都说不错
s*n
13 楼
觉得那个不太好,用share pointer:
class COWString {
share_ptr data;
public:
COWString(const char* input)
{
data = share_ptr(new CString(input));
}
COWString(const COWString& str)
{
data = str.data;
}
COWString& operator=(const COWString& str)
{
data = str.data;
return *this;
}
COWString& SetAt(int index, char c)
{
CString* newStr = new CString(data->c_str());
newStr->SetAt(index, c);
data = share_ptr(newStr);
return *this;
}
char GetAt(int index) const
{
return data->GetAt(index);
}
}
updating
【在 r*****b 的大作中提到】
: I think that it is more complex that this. We need to consider both updating
: the whole string, and updating one character in the string.
: Here is what I thought about the implementation:
: http://basicalgos.blogspot.com/2012/03/16-implement-copy-on-wri
class COWString {
share_ptr
public:
COWString(const char* input)
{
data = share_ptr
}
COWString(const COWString& str)
{
data = str.data;
}
COWString& operator=(const COWString& str)
{
data = str.data;
return *this;
}
COWString& SetAt(int index, char c)
{
CString* newStr = new CString(data->c_str());
newStr->SetAt(index, c);
data = share_ptr
return *this;
}
char GetAt(int index) const
{
return data->GetAt(index);
}
}
updating
【在 r*****b 的大作中提到】
: I think that it is more complex that this. We need to consider both updating
: the whole string, and updating one character in the string.
: Here is what I thought about the implementation:
: http://basicalgos.blogspot.com/2012/03/16-implement-copy-on-wri
h*g
15 楼
写了一个,有错误请指正~~
//copy on write
class String
{
private:
char *str;
int len;
public:
String():str(0),len(0)
{
}
String(char *p)
{
len=strlen(p);
char *tm=new char(len+2);
memset(tm,0,len+2);
str=tm+1;
strncpy(str,p,len+1);
}
String(const String &ms)
{
len=ms.len;
str=ms.str;
++(str[-1]);
}
String & operator =(const String &ms)
{
ms.str[-1]++;
descUse();
str=ms.str;
len=ms.len;
return *this;
}
void descUse()
{
str[-1]--;
if(str[-1]==-1)
{
delete str;
str=NULL;
len=0;
}
}
char & opeator[](int idx)
{
if(idx<0||idx>len)
{
return NULL;
}
if(str[-1]>0)
{
char *tmp=new char(len+2);
memset(tmp,0,len+2);
strncpy(tmp+1,str,len+1);
str[-1]--;
str=tmp+1;
}
return str[idx];
}
~String()
{
descUse();
}
};
【在 r*****k 的大作中提到】
: implement copy on write string class in c++
//copy on write
class String
{
private:
char *str;
int len;
public:
String():str(0),len(0)
{
}
String(char *p)
{
len=strlen(p);
char *tm=new char(len+2);
memset(tm,0,len+2);
str=tm+1;
strncpy(str,p,len+1);
}
String(const String &ms)
{
len=ms.len;
str=ms.str;
++(str[-1]);
}
String & operator =(const String &ms)
{
ms.str[-1]++;
descUse();
str=ms.str;
len=ms.len;
return *this;
}
void descUse()
{
str[-1]--;
if(str[-1]==-1)
{
delete str;
str=NULL;
len=0;
}
}
char & opeator[](int idx)
{
if(idx<0||idx>len)
{
return NULL;
}
if(str[-1]>0)
{
char *tmp=new char(len+2);
memset(tmp,0,len+2);
strncpy(tmp+1,str,len+1);
str[-1]--;
str=tmp+1;
}
return str[idx];
}
~String()
{
descUse();
}
};
【在 r*****k 的大作中提到】
: implement copy on write string class in c++
r*k
19 楼
阿三面的
implement copy on write string class in c++
implement copy on write string class in c++
s*n
21 楼
就是写两个overload吧?
COWString& operator=(const char*)
COWString& operator=(const COWString&)
COWString& operator=(const char*)
COWString& operator=(const COWString&)
q*c
22 楼
什么叫copy on write? 不懂这个,那一电面不歇菜了? 不是说F止考算法和数据结构吗
?
?
r*b
23 楼
I think that it is more complex that this. We need to consider both updating
the whole string, and updating one character in the string.
Here is what I thought about the implementation:
http://basicalgos.blogspot.com/2012/03/16-implement-copy-on-wri
【在 s******n 的大作中提到】
: 就是写两个overload吧?
: COWString& operator=(const char*)
: COWString& operator=(const COWString&)
the whole string, and updating one character in the string.
Here is what I thought about the implementation:
http://basicalgos.blogspot.com/2012/03/16-implement-copy-on-wri
【在 s******n 的大作中提到】
: 就是写两个overload吧?
: COWString& operator=(const char*)
: COWString& operator=(const COWString&)
S*y
24 楼
Re
p*2
25 楼
不懂呀。
s*n
26 楼
觉得那个不太好,用share pointer:
class COWString {
share_ptr data;
public:
COWString(const char* input)
{
data = share_ptr(new CString(input));
}
COWString(const COWString& str)
{
data = str.data;
}
COWString& operator=(const COWString& str)
{
data = str.data;
return *this;
}
COWString& SetAt(int index, char c)
{
CString* newStr = new CString(data->c_str());
newStr->SetAt(index, c);
data = share_ptr(newStr);
return *this;
}
char GetAt(int index) const
{
return data->GetAt(index);
}
}
updating
【在 r*****b 的大作中提到】
: I think that it is more complex that this. We need to consider both updating
: the whole string, and updating one character in the string.
: Here is what I thought about the implementation:
: http://basicalgos.blogspot.com/2012/03/16-implement-copy-on-wri
class COWString {
share_ptr
public:
COWString(const char* input)
{
data = share_ptr
}
COWString(const COWString& str)
{
data = str.data;
}
COWString& operator=(const COWString& str)
{
data = str.data;
return *this;
}
COWString& SetAt(int index, char c)
{
CString* newStr = new CString(data->c_str());
newStr->SetAt(index, c);
data = share_ptr
return *this;
}
char GetAt(int index) const
{
return data->GetAt(index);
}
}
updating
【在 r*****b 的大作中提到】
: I think that it is more complex that this. We need to consider both updating
: the whole string, and updating one character in the string.
: Here is what I thought about the implementation:
: http://basicalgos.blogspot.com/2012/03/16-implement-copy-on-wri
h*g
27 楼
写了一个,有错误请指正~~
//copy on write
class String
{
private:
char *str;
int len;
public:
String():str(0),len(0)
{
}
String(char *p)
{
len=strlen(p);
char *tm=new char(len+2);
memset(tm,0,len+2);
str=tm+1;
strncpy(str,p,len+1);
}
String(const String &ms)
{
len=ms.len;
str=ms.str;
++(str[-1]);
}
String & operator =(const String &ms)
{
ms.str[-1]++;
descUse();
str=ms.str;
len=ms.len;
return *this;
}
void descUse()
{
str[-1]--;
if(str[-1]==-1)
{
delete str;
str=NULL;
len=0;
}
}
char & opeator[](int idx)
{
if(idx<0||idx>len)
{
return NULL;
}
if(str[-1]>0)
{
char *tmp=new char(len+2);
memset(tmp,0,len+2);
strncpy(tmp+1,str,len+1);
str[-1]--;
str=tmp+1;
}
return str[idx];
}
~String()
{
descUse();
}
};
【在 r*****k 的大作中提到】
: 阿三面的
: implement copy on write string class in c++
//copy on write
class String
{
private:
char *str;
int len;
public:
String():str(0),len(0)
{
}
String(char *p)
{
len=strlen(p);
char *tm=new char(len+2);
memset(tm,0,len+2);
str=tm+1;
strncpy(str,p,len+1);
}
String(const String &ms)
{
len=ms.len;
str=ms.str;
++(str[-1]);
}
String & operator =(const String &ms)
{
ms.str[-1]++;
descUse();
str=ms.str;
len=ms.len;
return *this;
}
void descUse()
{
str[-1]--;
if(str[-1]==-1)
{
delete str;
str=NULL;
len=0;
}
}
char & opeator[](int idx)
{
if(idx<0||idx>len)
{
return NULL;
}
if(str[-1]>0)
{
char *tmp=new char(len+2);
memset(tmp,0,len+2);
strncpy(tmp+1,str,len+1);
str[-1]--;
str=tmp+1;
}
return str[idx];
}
~String()
{
descUse();
}
};
【在 r*****k 的大作中提到】
: 阿三面的
: implement copy on write string class in c++
l*y
29 楼
#include
#include
#include
#include
#include
#include
#include
using namespace std;
class Counter {
public :
Counter() {
counter = 0;
}
void increment() {
counter++;
}
void decrement() {
counter --;
}
int getValue() {
return counter;
}
private:
int counter;
};
class COWString {
public:
COWString() {
pointer = NULL;
rc = new Counter();
}
COWString(string& s) {
pointer = new string(s);
rc = new Counter();
rc->increment();
}
COWString(const COWString& cows) {
pointer = cows.pointer;
rc = cows.rc;
rc->increment();
}
COWString(COWString* const & cows) {
pointer = cows->pointer;
rc = cows->rc;
rc->increment();
}
COWString& operator= (const COWString& rhs) {
if (this == & rhs) {
return *this;
}
pointer = rhs.pointer;
rc = rhs.rc;
rc->increment();
return *this;
}
~COWString() {
rc->decrement();
if (rc->getValue() == 0) {
delete pointer;
delete rc;
}
}
char charAt(int index) {
return pointer->at(index);
}
void set(int index, char c) {
string* newpointer = new string(*pointer);
Counter* newrc = new Counter();
rc->decrement();
if (rc->getValue() == 0) {
delete pointer;
delete rc;
}
newpointer->at(index) = c; //问题//
newrc->increment();
pointer = newpointer;
rc = newrc;
}
string getData() {
return *pointer;
}
Counter* getCounter() {
return rc;
}
private:
string* pointer;
Counter* rc;
};
int main() {
string input = "hello world!";
COWString* s = new COWString(input);
COWString* copy = new COWString(const_cast (s));
cout << s->getData() << endl;
cout << s->getCounter()->getValue() << endl;
cout << copy->getData() << endl;
cout << copy->getCounter()->getValue() << endl;
copy->set(0, 'H');
cout << s->getData() << endl;
cout << s->getCounter()->getValue() << endl;
cout << copy->getData() << endl;
cout << copy->getCounter()->getValue() << endl;
return 0;
}
我也写了一个。 顺便问一个问题,在程序中为什么
newpointer->at(index) = c;
改成
newpointer[index] = c之后,结果就不对了。 谢谢!
#include
#include
#include
#include
#include
#include
using namespace std;
class Counter {
public :
Counter() {
counter = 0;
}
void increment() {
counter++;
}
void decrement() {
counter --;
}
int getValue() {
return counter;
}
private:
int counter;
};
class COWString {
public:
COWString() {
pointer = NULL;
rc = new Counter();
}
COWString(string& s) {
pointer = new string(s);
rc = new Counter();
rc->increment();
}
COWString(const COWString& cows) {
pointer = cows.pointer;
rc = cows.rc;
rc->increment();
}
COWString(COWString* const & cows) {
pointer = cows->pointer;
rc = cows->rc;
rc->increment();
}
COWString& operator= (const COWString& rhs) {
if (this == & rhs) {
return *this;
}
pointer = rhs.pointer;
rc = rhs.rc;
rc->increment();
return *this;
}
~COWString() {
rc->decrement();
if (rc->getValue() == 0) {
delete pointer;
delete rc;
}
}
char charAt(int index) {
return pointer->at(index);
}
void set(int index, char c) {
string* newpointer = new string(*pointer);
Counter* newrc = new Counter();
rc->decrement();
if (rc->getValue() == 0) {
delete pointer;
delete rc;
}
newpointer->at(index) = c; //问题//
newrc->increment();
pointer = newpointer;
rc = newrc;
}
string getData() {
return *pointer;
}
Counter* getCounter() {
return rc;
}
private:
string* pointer;
Counter* rc;
};
int main() {
string input = "hello world!";
COWString* s = new COWString(input);
COWString* copy = new COWString(const_cast
cout << s->getData() << endl;
cout << s->getCounter()->getValue() << endl;
cout << copy->getData() << endl;
cout << copy->getCounter()->getValue() << endl;
copy->set(0, 'H');
cout << s->getData() << endl;
cout << s->getCounter()->getValue() << endl;
cout << copy->getData() << endl;
cout << copy->getCounter()->getValue() << endl;
return 0;
}
我也写了一个。 顺便问一个问题,在程序中为什么
newpointer->at(index) = c;
改成
newpointer[index] = c之后,结果就不对了。 谢谢!
w*x
31 楼
明显的刁难嘛(除非楼主简历上写了会这个), 大家就别讨论了
相关阅读
急求:新房油烟机抉择---谢谢dishnetwork优惠急问:关于radon test。 Home Inspector 说的 和 test kit 的 instruction 不一样。这两个冰箱你们更prefer哪一个?用Refin上的buyer agent能拿到%多少的rebate?真皮沙发是否只是坐垫,靠背和扶手部分是真皮的?也问个高处的窗户遮阳的问题种草前的准备:砍树和圈狗ING贷款renew+可以重新洗牌吗?有没有适合2岁小孩的剪剪贴贴的书? (转载)怎么网上看电视?spinkler system的设计需要注意哪些问题那?请问RUBY在哪儿买好?耳环 (转载)请问short sell的话,agent的作用有多大买卖房子一定要agent么?政府的房屋估价护家终极解决方案装木地板的人家里地下室都要装dehumidifier么?最近DISH有什么优惠吗? (转载)请问:直接找卖家Agent真的会减价更多吗?