我有一个组件,它具有与组件本身相同类型的子组件.我也可以渲染孩子,但孩子似乎无法进入他们的状态.我正在使用React和Redux
export class Material extends React.Component {
constructor(props) {
super(props)
this.renderChild = this.renderChild.bind(this)
this.getNestedItems = this.getNestedItems.bind(this)
}
static propTypes = {
parentId: PropTypes.number,
id: PropTypes.number.isRequired,
name: PropTypes.string.isRequired,
subtext: PropTypes.string.isRequired,
childIds: PropTypes.arrayOf(PropTypes.number.isRequired),
fileType: PropTypes.string.isRequired
}
// This is where I am having trouble.
// Shouldn't the props be accessible from state itself?
renderChild = (id, childId) => (
<Material key={childId}
id={childId}
parentId={id}
name={name}
subtext={subtext}
fileType={fileType}
/>
)
getNestedItems = (id, childIds) => {
console.log("id: " + id)
console.log("childIds: " + childIds) …Run Code Online (Sandbox Code Playgroud) 我认为它是O(1),但这是来自pprof输出:
140 140 176: var lastSB byte = s[lenSMinusOne]
88 88 177: var lastSuffixB byte = suffix[lenSuffixMinusOne]
Run Code Online (Sandbox Code Playgroud)
并且平均长度s大于后缀的长度.因此,这表明如果切片更大,访问元素需要更长的时间?
功能是:
func hasSuffix(s, suffix []byte) bool {
lenSMinusOne := len(s) - 1
lenSuffixMinusOne := len(suffix) - 1
var lastSB byte = s[lenSMinusOne]
var lastSuffixB byte = suffix[lenSuffixMinusOne]
if lenSMinusOne < lenSuffixMinusOne {
return false
} else if lastSB != lastSuffixB {
return false
} else {
for i := 0; i < lenSuffixMinusOne ; i++ {
if suffix[i] != s[lenSMinusOne-lenSuffixMinusOne+i] {
return …Run Code Online (Sandbox Code Playgroud) Codechef中最简单的问题是读取输入和写入输出,只要数字不是42.我编写了以下代码:
package main
import "fmt"
func main() {
var num int8
fmt.Scanln(&num)
for ; num != 42; fmt.Scanln(&num) {
fmt.Println(num)
}
}
Run Code Online (Sandbox Code Playgroud)
它被接受,但根据网站使用124.6M内存.我在C中写了基本相同的东西,花了1.6M,我很困惑.你知道这可能导致了什么吗?
我是Go的新手.这可能是一个大胆的错误.