GithubHelp home page GithubHelp logo

Comments (3)

ccoder64 avatar ccoder64 commented on June 18, 2024

同样疑惑。
过来确认的时候发现,15年以后就没更新了。。

from redis-3.0-annotated.

hfdpx avatar hfdpx commented on June 18, 2024

同样的疑惑,过来确认一下我没错

from redis-3.0-annotated.

vicksiyi avatar vicksiyi commented on June 18, 2024

sds sdstrim(sds s, const char *cset)
{
struct sdshdr *sh = (void *)(s - (sizeof(struct sdshdr)));
char *start, *end, *sp, *ep;
size_t len;

// 设置和记录指针
sp = start = s;
ep = end = s + sdslen(s) - 1;

// 修剪, T = O(N^2)  ===========================>这里是不是也错了???
while (sp <= end && strchr(cset, *sp))
    sp++;
while (ep > start && strchr(cset, *ep))
    ep--;

// 计算 trim 完毕之后剩余的字符串长度
len = (sp > ep) ? 0 : ((ep - sp) + 1);

// 如果有需要,前移字符串内容
// T = O(N)
if (sh->buf != sp)
    memmove(sh->buf, sp, len);

// 添加终结符
sh->buf[len] = '\0';

// 更新属性
sh->free = sh->free + (sh->len - len);
sh->len = len;

// 返回修剪后的 sds
return s;

}

from redis-3.0-annotated.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.