发表于 2024年7月20日1年前 玩具项目,不过真的很好玩!```cint prime_factor_co(Co *co, void *data){ PrimeFactorData *pfData = (PrimeFactorData *)data; CO_BEGIN(co); pfData->current = 2; while (pfData->number > 1) { while (pfData->number % pfData->current == 0) { pfData->number /= pfData->current; pfData->factor = pfData->current; CO_YIELD(co, pfData->factor); } pfData->current++; CO_YIELD(co, 0); // Yield to indicate progress } CO_END(co); return 0;}```https://zhuanlan.zhihu.com/p/710329144https://github.com/pluveto/minico
```c
int prime_factor_co(Co *co, void *data)
{
PrimeFactorData *pfData = (PrimeFactorData *)data;
CO_BEGIN(co);
pfData->current = 2;
while (pfData->number > 1)
{
while (pfData->number % pfData->current == 0)
{
pfData->number /= pfData->current;
pfData->factor = pfData->current;
CO_YIELD(co, pfData->factor);
}
pfData->current++;
CO_YIELD(co, 0); // Yield to indicate progress
}
CO_END(co);
return 0;
}
```
https://zhuanlan.zhihu.com/p/710329144
https://github.com/pluveto/minico