八分之一仅使用一到三个(八进制)数字 -   “ \ 033999c”
是5个字符加上一个null字节。
十六进制逃脱使用的数字数量如 \ x
序列。因此,“ \ x1b999c”
包含一个单个十六进制字符常数。
至少有两个可能的修复程序。一种是编码 \ x1b
为 \ 033
(或 \ 33
- 它们是相同的,尽管如果之后的文本\ x1b
是 777a
而不是 999c
,那么三位数的八位ovene是必需的
if (write(STDOUT_FILENO, "\033999C\033999B", 10) != 10)
。串联:
if (write(STDOUT_FILENO, "\x1B" "999C" "\x1B" "999B", 10) != 10)
这是因为在 - 第5阶段转换逃脱序列,第6阶段结合了相邻的字符串文字
。这是10个非挂钩字符 - 如果您打算编写字节0x01,然后是5个字符(两次),那么12个字符更有意义,并且您需要更改字符串中断的地方
。 > 11 :
#include <stdio.h>
int main(void)
{
char data[] = "\x1b" "999C" "\x1b" "999B";
printf("%zu\n", sizeof(data));
return 0;
}
删除序列,GCC投资:
xe43.c: In function ‘main’:
xe43.c:5:19: error: hex escape sequence out of range [-Werror]
char data[] = "\x1b999C\x1b999B";
^~~~~~~~~~~~~~~~~~
xe43.c:5:19: error: hex escape sequence out of range [-Werror]
cc1: all warnings being treated as errors
我使用 Werror
选项进行编译,否则,只有警告没有 -werror
并运行,它会产生答案3,而不是11。
看起来您已经弄清楚了,但是对于遇到这个问题的其他任何人来说,多年来失败的射线广播中的Unity行为发生了变化。
这些天,您还应该能够检查命中率是否为空。
并命中率,如果命中率为null,则应丢下错误。
检查物理的结果。raycast是必经之路。
此处提供的所有出色答案都集中在原始海报的具体要求上,并集中于
{x,y,z} in {x,y,z} 的解决方案。
他们忽略的是这个问题的更广泛含义:
如何针对多个值测试一个变量?
如果使用字符串,则提供的解决方案对部分命中无效:
测试字符串“野生”是否在多个值中
>>> x = "Wild things"
>>> y = "throttle it back"
>>> z = "in the beginning"
>>> if "Wild" in {x, y, z}: print (True)
...
,或者
>>> x = "Wild things"
>>> y = "throttle it back"
>>> z = "in the beginning"
>>> if "Wild" in [x, y, z]: print (True)
...
在这种情况下,最容易转换为字符串,
>>> [x, y, z]
['Wild things', 'throttle it back', 'in the beginning']
>>> {x, y, z}
{'in the beginning', 'throttle it back', 'Wild things'}
>>>
>>> if "Wild" in str([x, y, z]): print (True)
...
True
>>> if "Wild" in str({x, y, z}): print (True)
...
True
则应注意,如 @codeforester
所述,该方法范围丢失了此方法,如:
>>> x=['Wild things', 'throttle it back', 'in the beginning']
>>> if "rot" in str(x): print(True)
...
True
3个字母 rot
确实存在于列表中,但不是单个单词。对“腐烂”的测试将失败,但是如果列表项目之一是“地狱中的腐烂”,那也将失败。
结果是,如果使用此方法,请注意您的搜索标准,并注意它确实有此限制。
完全不要写循环。您对列表中应发生的元素的期望是什么?sup> 1 ?从您的样本中看来,它应该至少一次,但可能完全是一次。
然后选择适当的表达您的期望清楚地表达了:
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main()
{
List<string> l = new List<string> { "one", "two", "three" };
string j = l.Single(item=>item=="one");
Console.WriteLine(j);
}
}
如果一个元素完全不符合我们的标准,则以上会引发异常。您可以选择第一个
或最后一个
(或带有 ordeffault
)变体以表达您的要求和期望。
1 或换句话说,如果列表为空或列表中没有元素与您的搜索条件匹配您的期望是什么?
您的Python代码似乎只是假设两个都不是真实的。 C#旨在帮助您发现诸如此类摇摇欲坠的假设即将发挥作用的地方,并防止您以这种假设编写代码。
从历史上看,未分配的变量一直是很难追踪错误的巨大来源,因为它们要么包含垃圾(通常但并非总是很快就会引起错误)或默认值(在相当长的一段时间内看起来像是真正的价值),症状在与破裂的假设完全不同的位置出现。
带有2个硬件内核的处理器一次可以在两个线程上工作吗?
是的,...
...但是,想象一下自己回到维多利亚时代,雇用一堆文员来执行复杂的计算。他们需要的所有数据都在一本书中,他们应该将所有结果写回同一本书。
这本书就像计算机的内存一样,店员就像单独的CPU。由于只有一个店员可以在任何给定时间使用这本书,因此似乎没有多个以上的人,... ...
...除非您给每个店员一个记事本。他们可以去书籍,复制一些数字,然后在他们自己的记事本上工作一段时间,然后才返回从记事本的部分结果复制到书中的部分结果。这允许其他文员在书籍中任何一个文员时做一些有用的工作。
记事本就像是计算机的级别1个缓存与单个CPU关联的内存,并保存已读取的数据副本,或者需要写回主内存。计算机硬件会根据需要自动复制主内存和缓存之间的数据,因此程序不一定需要意识到缓存甚至存在。 (请参阅 https://en.wikipedia.org/wiki/wiki/cache_coherence )
但是, em>程序员应该注意:如果您可以构建程序,以便将不同的线程花费大部分时间读取和编写私人变量,并且相对较少的时间访问与其他线程共享的变量,那么大多数私有变量访问将不超过L1缓存,并且线程将能够并行运行。另一方面,如果所有线程都尝试同时使用相同的变量,或者如果线程都尝试在大量数据上迭代(太大而无法适合缓存),那么它们的能力将较少。并行工作。
另请参阅:
这可能很棘手。
考虑一下它的一种方法是,您需要确定导入路径的根,然后原始导入是相对于它的。
假设 $ {PWD}
是 Protos
的父。
示例#1:
如果您使用 $ {pwd}
作为 proto_path
:
protoc \
--proto_path=${PWD} \
--go_out=${PWD} \
${PWD}/protos/auth/auth_service.proto \
${PWD}/protos/auth/user.proto
导入应为导入“ protos/auth/auth/user.proto”;
示例#2:
如果您使用 Protos
作为 proto_path
:
protoc \
--proto_path=${PWD}/protos \
--go_out=${PWD} \
${PWD}/protos/auth/auth_service.proto \
${PWD}/protos/auth/user.proto
导入应为导入“ auth/user.proto”;
。
注释在所有情况下,
proto
文件参考必须由(之一)proto_path之一
。。
settings.json
:
"protoc": {
"path": "${workspaceRoot}/protoc-21.2-linux-x86_64/bin/protoc",
"compile_on_save": true,
"options": [
"--proto_path=${workspaceRoot}/protoc-21.2-linux-x86_64/include",
"--proto_path=${workspaceRoot}/protos",
"--go_out=${workspaceRoot}"
]
}
我会使用脚本
int n=4;
range r=1..n;
int a[r]=[1,3,2,5];
tuple t
{
key int rank;
int value;
}
{t} s={};
execute
{
var rank=0;
for(var i in r)
{
for(var j=1;j<=a[i];j++)
{
rank++;
s.add(rank,a[i])
}
}
}
int b[k in 1..card(s)]=item(s,<k>).value;
execute
{
writeln(b);
}
给
[1 3 3 3 2 2 5 5 5 5 5]
这是 Dintictby
方法的通用实现,该方法返回了组的最后记录。
示意性地进行以下调用时:
query = query.DistinctBy(e => e.EmpId, e => e.EffectiveDt);
// or with complex keys
query = query.DistinctBy(e => new { e.EmpId, e.Other }, e => new { e.EffectiveDt, e.SomeOther});
或完全动态
query = query.DistinctBy("EmpId", "EffectiveDt");
函数会生成以下查询:
query =
from d in query.Select(d => d.EmpId).Distinct()
from e in query
.Where(e => e.EmpId == d)
.OrderByDescending(e => e.EffectiveDt)
.Take(1)
select e;
或使用复杂的键:
query =
from d in query.Select(d => new { d.EmpId, d.Other }).Distinct()
from e in query
.Where(e => e.EmpId == d.EmpId && e.Other == d.Other)
.OrderByDescending(e => e.EffectiveDt)
.ThenByDescending(e => e.SomeOther)
.Take(1)
select e;
实现:
public static class QueryableExtensions
{
public static IQueryable<T> DistinctBy<T>(
this IQueryable<T> source,
string distinctPropName,
string maxPropName)
{
var entityParam = Expression.Parameter(typeof(T), "e");
var distinctBy = Expression.Lambda(MakePropPath(entityParam, distinctPropName), entityParam);
var maxBy = Expression.Lambda(MakePropPath(entityParam, maxPropName), entityParam);
var queryExpression = Expression.Call(typeof(QueryableExtensions), nameof(QueryableExtensions.DistinctBy),
new[] { typeof(T), distinctBy.Body.Type, maxBy.Body.Type },
Expression.Constant(source),
Expression.Quote(distinctBy),
Expression.Quote(maxBy));
var executionLambda = Expression.Lambda<Func<IQueryable<T>>>(queryExpression);
return executionLambda.Compile()();
}
public static IQueryable<T> DistinctBy<T, TKey, TMax>(
this IQueryable<T> source,
Expression<Func<T, TKey>> distinctBy,
Expression<Func<T, TMax>> maxBy)
{
var distinctQuery = source.Select(distinctBy).Distinct();
var distinctParam = Expression.Parameter(typeof(TKey), "d");
var entityParam = distinctBy.Parameters[0];
var mapping = MapMembers(distinctBy.Body, distinctParam).ToList();
var orderParam = maxBy.Parameters[0];
var oderMapping = CollectMembers(maxBy.Body).ToList();
var whereExpr = mapping.Select(t => Expression.Equal(t.Item1, t.Item2))
.Aggregate(Expression.AndAlso);
var whereLambda = Expression.Lambda(whereExpr, entityParam);
// d => query.Where(x => d.distinctBy == x.distinctBy).Take(1)
Expression selectExpression = Expression.Call(typeof(Queryable), nameof(Queryable.Where), new[] { typeof(T) },
source.Expression,
whereLambda);
// prepare OrderByPart
for (int i = 0; i < oderMapping.Count; i++)
{
var orderMethod = i == 0 ? nameof(Queryable.OrderByDescending) : nameof(Queryable.ThenByDescending);
var orderItem = oderMapping[i];
selectExpression = Expression.Call(typeof(Queryable), orderMethod, new[] { typeof(T), orderItem.Type },
selectExpression, Expression.Lambda(orderItem, orderParam));
}
// Take(1)
selectExpression = Expression.Call(typeof(Queryable), nameof(Queryable.Take), new[] { typeof(T) },
selectExpression,
Expression.Constant(1));
var selectManySelector =
Expression.Lambda<Func<TKey, IEnumerable<T>>>(selectExpression, distinctParam);
var selectManyQuery = Expression.Call(typeof(Queryable), nameof(Queryable.SelectMany),
new[] { typeof(TKey), typeof(T) }, distinctQuery.Expression, selectManySelector);
return source.Provider.CreateQuery<T>(selectManyQuery);
}
static Expression MakePropPath(Expression objExpression, string path)
{
return path.Split('.').Aggregate(objExpression, Expression.PropertyOrField);
}
private static IEnumerable<Tuple<Expression, Expression>> MapMembers(Expression expr, Expression projectionPath)
{
switch (expr.NodeType)
{
case ExpressionType.New:
{
var ne = (NewExpression)expr;
for (int i = 0; i < ne.Arguments.Count; i++)
{
foreach (var e in MapMembers(ne.Arguments[i], Expression.MakeMemberAccess(projectionPath, ne.Members[i])))
{
yield return e;
}
}
break;
}
default:
yield return Tuple.Create(projectionPath, expr);
break;
}
}
private static IEnumerable<Expression> CollectMembers(Expression expr)
{
switch (expr.NodeType)
{
case ExpressionType.New:
{
var ne = (NewExpression)expr;
for (int i = 0; i < ne.Arguments.Count; i++)
{
yield return ne.Arguments[i];
}
break;
}
default:
yield return expr;
break;
}
}
}
基于范围的循环(<代码>(t i:v)内部使用 std ::开始和, std :: list
或任何具有 .begin()
和 .end> .end()的类返回迭代器,
,它确实适用于指针。
但是 代码>。指针。
那么如何为数组创建调试?
如果要使用动态分配的数组,则必须将数组大小传递
template <class T> void print(T v[], size_t size)
给循环的正常大小
for(size_t i = 0; i < size; i++) { ... }
,另一种可能性是为数组大小制作模板,例如:有人可以解释这个模板代码,以使我有一个数组的大小?
更新:进一步谷歌搜索,我发现了这一点: https://github.com/rails/rails/rails/rails/rails/rails/rails/issues/issues/issues/issues/issues/issues /44185 ,有一个对我有用的解决方案。
基本上,方法
被弃用,而新方法是使用
data: { turbo_method: :delete, turbo_confirm: "Are you sure?" }
。如果这不起作用,请尝试
rails importmap:install
rails turbo:install stimulus:install
先运行命令。
至少对我有用。
如果您提供明确的断点列表, ggplot
将“服从”。因此,您可以使用以下代码:
ggplot(data=df, aes(x=date, y=value)) +
geom_line(linetype='solid', alpha = 1, size = 1.5, color='blue') +
geom_point(alpha = 1, size = 4, color='blue') +
scale_x_date(breaks = as.Date(c("2022-07-31", "2022-08-31", "2022-09-30", "2022-10-31")))
甚至更短:
ggplot(data=df, aes(x=date, y=value)) +
geom_line(linetype='solid', alpha = 1, size = 1.5, color='blue') +
geom_point(alpha = 1, size = 4, color='blue') +
scale_x_date(breaks = df$date)
产生此图:
解决方案似乎很琐碎,所以我必须问:这是您所追求的吗?
编辑
如果您有许多数据点,则相同的原理具有。绘制您的数据,但要明确分配休息时间,例如在以下代码中:
(此外,标签被旋转45°),
## mock-up data
df2 <- structure(list(date = structure(seq(19204, 19296, 1), class = "Date"),
value = c(seq(3.5, 3.6, length.out = 31),
seq(3.6, 4.05, length.out = 31),
seq(4.05, 4.13, length.out = 31)) ),
row.names = c(NA, -93L),
class = "data.frame")
## define my_breaks
my_breaks = as.Date(c("2022-07-31", "2022-08-31", "2022-09-30", "2022-10-31"))
ggplot(data=df2, aes(x=date, y=value)) +
geom_line(linetype='solid', alpha = 1, size = 1.5, color='blue') +
geom_point(alpha = 1, size = 3, color='blue') +
scale_x_date(breaks = my_breaks) + ## breaks
theme(axis.text.x = element_text(angle = 45, hjust = 1)) ## rotate
该标签得出以下图:
替换此段:
+ ",CCCC," + ",," + ",," +
随之而来的是:
+ ",CCCC,,," +
但是您将在专用的CSV库中更好地做 ,其中Nuget上有几种不错的选择。
此外,如果您使用的是 StringBuilder
,因为您听说它更快,请记住,更快的是相对的。 StringBuilder
的速度比此类工作的字符串串联要快,但是如果您最终要写入网络流,文件或Web响应
在VSCODE中,我试图禁用我之前安装的所有扩展程序,我一个一个接一个地禁用它们,在每次禁用后,我通过更改代码然后保存的代码测试,但问题仍然存在,直到所有扩展名关闭为止。
然后我想起还有其他一些内置扩展。我打开了扩展名,然后按在左侧栏右上方的三个点上,然后我选择
显示运行扩展
,运行扩展
将打开,您将找到其中的git。我注意到git在无响应中,除了4000+MS
之外,它的数量大于所有其他扩展。请注意,我正在使用git版本
2.34.1
。在生锈开发过程中,GIT扩展也可以响应。因此,我将git更新为最新版本,该版本是
2.37.1
使用以下命令:sudo addo add-apt-repository ppa:git-core/ppa
sudo apt apt Update
sudo apt install git
现在我重新启动了VSCODE,git扩展程序响应且正常工作。另外,节省很快,一切都很好。
问题归因于我所知,仅在C ++开发中扩展了无反应的GIT。因此,将git更新到最新版本。
更新:
我认为即使将GIT更新为最新版本后,问题仍然存在。延迟仍然仅在C ++开发中发生。一旦我使用
git Init
在工作目录中初始化了git,就可以解决该问题。当我重新启动VSCODE时,一切正常。这是问题存在时运行扩展的屏幕截图(请注意第一个GIT扩展程序):更新:
我想我知道问题所在。我的C ++项目的目录是
/home/user/user/projects/cpp/testing_1
,在cpp/
目录中,我放置了所有我的C ++项目,例如testing_1/< /code>,
testing_2/
等等。我在cpp/
dir中初始化的git在此之前是我所有项目的父级。当我删除.git
cpp/
dir时,即使我在工作项目中不初始化git,例如testing_1 /
。我认为您的项目的父母dir中不初始化git解决了问题。我会看到那走的地方。In vscode, i tried to disable all the extensions that i installed previously, i disabled them one by one, after each disable, i test by changing the code then saving, yet the problem persists, until all the extensions are off.
Then i remembered there are some other built-in extensions. I opened the extensions, then pressed on the three dots at the top right of the left side bar, then i chose
Show running extensions
, theRunning extensions
will open and you will find among them git. I noticed that git in unresponsive and had a huge number beside it like4000+ms
which is substantially greater than all the other extensions.Notice that i am using git version
2.34.1
. Also the git extension is ok and responsive during Rust development.So i updated git to the latest version which is
2.37.1
using these commands:sudo add-apt-repository ppa:git-core/ppa
sudo apt update
sudo apt install git
Now i restarted vscode and the git extension is responsive and working properly. Also the saving is fast and everything in fine.
The problem was due to unresponsive git extension only in C++ development as far as i know. So update git to the latest version.
Update:
I think the problem still exists even after i updated git to the latest version. The delay still only happens with C++ development. The problem is solved once i initialized git in my working directory using

git init
. When i restart vscode, everything works fine. Here is a screenshot of the Running extensions when the problem exists (Notice the first git extension):Update:
I think i knew where the problem is. The directory of my C++ project is
/home/user/Projects/cpp/testing_1
, incpp/
directory i put all my C++ projects such astesting_1/
,testing_2/
and so on. I initialized git incpp/
dir before which is the parent dir of all my projects. When i deleted that.git
dir incpp/
the git extension in responsive and working fine, even when i am not initializing git in my working project such astesting_1/
. I think not initializing git in the parent dir of your project solved the problem. I will see where that goes.VS代码需要几秒钟才能将文档保存在C&#x2B;&#x2B;