Go语言实现HashSet

set.go

// set project set.go
package settype Set interface {Add(e interface{}) boolRemove(e interface{})Clear()Contains(e interface{}) boolLen() intSame(other Set) boolElements() []interface{}String() string
}// 将集合other添加到集合one中
func AddSet(one Set, other Set) {if one == nil || other == nil || other.Len() == 0 {return}for _, v := range other.Elements() {one.Add(v)}
}// 判断集合 one 是否是集合 other 的超集
func IsSuperset(one Set, other Set) bool {if one == nil || other == nil {return false}oneLen := one.Len()otherLen := other.Len()if oneLen == 0 || oneLen <= otherLen {return false}if oneLen > 0 && otherLen == 0 {return true}for _, v := range other.Elements() {if !one.Contains(v) {return false}}return true
}// 生成集合 one 和集合 other 的并集
func Union(one Set, other Set) Set {if one == nil && other == nil {return nil}unionedSet := NewSimpleSet()AddSet(unionedSet, one)AddSet(unionedSet, other)return unionedSet
}// 生成集合 one 和集合 other 的交集
func Intersect(one Set, other Set) Set {if one == nil || other == nil {return nil}intersectedSet := NewSimpleSet()if one.Len() == 0 || other.Len() == 0 {return intersectedSet}if one.Len() < other.Len() {for _, v := range one.Elements() {if other.Contains(v) {intersectedSet.Add(v)}}} else {for _, v := range other.Elements() {if one.Contains(v) {intersectedSet.Add(v)}}}return intersectedSet
}// 生成集合 one 对集合 other 的差集
func Difference(one Set, other Set) Set {if one == nil {return nil}differencedSet := NewSimpleSet()if other == nil || other.Len() == 0 {AddSet(differencedSet, one)return differencedSet}for _, v := range one.Elements() {if !other.Contains(v) {differencedSet.Add(v)}}return differencedSet
}// 生成集合 one 和集合 other 的对称差集
func SymmetricDifference(one Set, other Set) Set {diffA := Difference(one, other)if other == nil || other.Len() == 0 {return diffA}diffB := Difference(other, one)return Union(diffA, diffB)
}// 返回一个HashSet
func NewSimpleSet() Set {return NewHashSet()
}// 判断给定value是否为集合
func IsSet(value interface{}) bool {if _, ok := value.(Set); ok {return true}return false
}

hash_set.go

// hash_set
package setimport ("bytes""fmt"
)type HashSet struct {m map[interface{}]bool
}// 创建和初始化HashSet的方法
func NewHashSet() *HashSet {return &HashSet{m: make(map[interface{}]bool)}
}// 向HashSet中添加元素的方法
func (set *HashSet) Add(e interface{}) bool {if !set.m[e] {set.m[e] = truereturn true}return false
}// 删除HashSet中指定的元素
func (set *HashSet) Remove(e interface{}) {delete(set.m, e)
}// 清除HashSet中的所有元素
func (set *HashSet) Clear() {set.m = make(map[interface{}]bool)
}// 判断HashSet是否包含指定元素
func (set *HashSet) Contains(e interface{}) bool {return set.m[e]
}// 获取HashSet中元素值数量
func (set *HashSet) Len() int {return len(set.m)
}// 判断两个Set类型值是否相同
func (set *HashSet) Same(other Set) bool {if other == nil {return false}if set.Len() != other.Len() {return false}for key := range set.m {if !other.Contains(key) {return false}}return true
}// 生成HashSet的一个快照
func (set *HashSet) Elements() []interface{} {initialLen := len(set.m)snapshot := make([]interface{}, initialLen)actualLen := 0for key := range set.m {if actualLen < initialLen {snapshot[actualLen] = key} else {snapshot = append(snapshot, key)}actualLen++}if actualLen < initialLen {snapshot = snapshot[:actualLen]}return snapshot
}// 获取HashSet自身字符串表示形式
func (set *HashSet) String() string {var buf bytes.Bufferbuf.WriteString("Set{")first := truefor key := range set.m {if first {first = false} else {buf.WriteString(" ")}buf.WriteString(fmt.Sprintf("%v", key))}buf.WriteString("}")return buf.String()
}

功能测试:

set_test.go

// set_test
package setimport ("bytes""fmt""math/rand""runtime/debug""strings""testing""time"
)func testSetLenAndContains(t *testing.T, newSet func() Set, typeName string) {t.Logf("Starting Test%sLenAndContains...", typeName)set, expectedElemMap := genRandSet(newSet)t.Logf("Got a %s value: %v.", typeName, set)expectedLen := len(expectedElemMap)if set.Len() != expectedLen {t.Errorf("ERROR: The length of %s value %d is not %d!\n",set.Len(), typeName, expectedLen)t.FailNow()}t.Logf("The length of %s value is %d.\n", typeName, set.Len())for k := range expectedElemMap {if !set.Contains(k) {t.Errorf("ERROR: The %s value %v do not contains %v!",set, typeName, k)t.FailNow()}}
}func testSetAdd(t *testing.T, newSet func() Set, typeName string) {t.Logf("Starting Test%sAdd...", typeName)set := newSet()var randElem interface{}var result boolexpectedElemMap := make(map[interface{}]bool)for i := 0; i < 5; i++ {randElem = genRandElement()t.Logf("Add %v to the %s value %v.\n", randElem, typeName, set)result = set.Add(randElem)if expectedElemMap[randElem] && result {t.Errorf("ERROR: The element adding (%v => %v) is successful but should be failing!\n",randElem, set)t.FailNow()}if !expectedElemMap[randElem] && !result {t.Errorf("ERROR: The element adding (%v => %v) is failing!\n",randElem, set)t.FailNow()}expectedElemMap[randElem] = true}t.Logf("The %s value: %v.", typeName, set)expectedLen := len(expectedElemMap)if set.Len() != expectedLen {t.Errorf("ERROR: The length of %s value %d is not %d!\n",set.Len(), typeName, expectedLen)t.FailNow()}t.Logf("The length of %s value is %d.\n", typeName, set.Len())for k := range expectedElemMap {if !set.Contains(k) {t.Errorf("ERROR: The %s value %v do not contains %v!",set, typeName, k)t.FailNow()}}
}func testSetRemove(t *testing.T, newSet func() Set, typeName string) {t.Logf("Starting Test%sRemove...", typeName)set, expectedElemMap := genRandSet(newSet)t.Logf("Got a %s value: %v.", typeName, set)t.Logf("The length of %s value is %d.\n", typeName, set.Len())var number intfor k, _ := range expectedElemMap {if number%2 == 0 {t.Logf("Remove %v from the HashSet value %v.\n", k, set)set.Remove(k)if set.Contains(k) {t.Errorf("ERROR: The element removing (%v => %v) is failing!\n",k, set)t.FailNow()}delete(expectedElemMap, k)}number++}expectedLen := len(expectedElemMap)if set.Len() != expectedLen {t.Errorf("ERROR: The length of HashSet value %d is not %d!\n", set.Len(), expectedLen)t.FailNow()}t.Logf("The length of %s value is %d.\n", typeName, set.Len())for _, v := range set.Elements() {if !expectedElemMap[v] {t.Errorf("ERROR: The HashSet value %v contains %v but should not contains!", set, v)t.FailNow()}}
}func testSetClear(t *testing.T, newSet func() Set, typeName string) {t.Logf("Starting Test%sClear...", typeName)set, _ := genRandSet(newSet)t.Logf("Got a %s value: %v.", typeName, set)t.Logf("The length of %s value is %d.\n", typeName, set.Len())t.Logf("Clear the HashSet value %v.\n", set)set.Clear()expectedLen := 0if set.Len() != expectedLen {t.Errorf("ERROR: The length of HashSet value %d is not %d!\n", set.Len(), expectedLen)t.FailNow()}t.Logf("The length of %s value is %d.\n", typeName, set.Len())
}func testSetElements(t *testing.T, newSet func() Set, typeName string) {t.Logf("Starting Test%sElements...", typeName)set, expectedElemMap := genRandSet(newSet)t.Logf("Got a %s value: %v.", typeName, set)t.Logf("The length of %s value is %d.\n", typeName, set.Len())elems := set.Elements()t.Logf("The elements of %s value is %v.\n", typeName, elems)expectedLen := len(expectedElemMap)if len(elems) != expectedLen {t.Errorf("ERROR: The length of HashSet value %d is not %d!\n", len(elems), expectedLen)t.FailNow()}t.Logf("The length of elements is %d.\n", len(elems))for _, v := range elems {if !expectedElemMap[v] {t.Errorf("ERROR: The elements %v contains %v but should not contains!", set, v)t.FailNow()}}
}func testSetSame(t *testing.T, newSet func() Set, typeName string) {t.Logf("Starting Test%sSame...", typeName)set, _ := genRandSet(newSet)t.Logf("Got a %s value: %v.", typeName, set)t.Logf("The length of %s value is %d.\n", typeName, set.Len())set2 := newSet()t.Logf("Clone the HashSet value %v...\n", set)for _, v := range set.Elements() {set2.Add(v)}result := set2.Same(set)if !result {t.Errorf("ERROR: Two sets are not same!")}t.Logf("Two sets are same.")
}func testSetString(t *testing.T, newSet func() Set, typeName string) {t.Logf("Starting Test%sString...", typeName)set, _ := genRandSet(newSet)t.Logf("Got a %s value: %v.", typeName, set)setStr := set.String()t.Logf("The string of %s value is %s.\n", typeName, setStr)var elemStr stringfor _, v := range set.Elements() {elemStr = fmt.Sprintf("%v", v)if !strings.Contains(setStr, elemStr) {t.Errorf("ERROR: The string of %s value %s do not contains %s!",typeName, setStr, elemStr)t.FailNow()}}
}// ----- Set 公用函数测试 -----

func TestIsSuperset(t *testing.T) {defer func() {if err := recover(); err != nil {debug.PrintStack()t.Errorf("Fatal Error: %s\n", err)}}()t.Log("Starting TestIsSuperset...")set, _ := genRandSet(func() Set { return NewSimpleSet() })set2 := NewSimpleSet()for _, v := range set.Elements() {set2.Add(v)}for extraElem := genRandElement(); ; {if set2.Add(extraElem) {break} else {time.Sleep(10 * time.Millisecond)}}if !IsSuperset(set2, set) {t.Errorf("ERROR: The HashSet value %v is not a superset of %v!\n", set2, set)t.FailNow()} else {t.Logf("The HashSet value %v is a superset of %v.\n", set2, set)}for extraElem := genRandElement(); ; {if set.Add(extraElem) {break} else {time.Sleep(10 * time.Millisecond)}}if IsSuperset(set2, set) {t.Errorf("ERROR: The HashSet value %v should not be a superset of %v!\n", set2, set)t.FailNow()} else {t.Logf("The HashSet value %v is not a superset of %v.\n", set2, set)}
}func TestUnion(t *testing.T) {defer func() {if err := recover(); err != nil {debug.PrintStack()t.Errorf("Fatal Error: %s\n", err)}}()t.Log("Starting TestUnion...")set, _ := genRandSet(func() Set { return NewSimpleSet() })t.Logf("The set value: %v", set)set2, _ := genRandSet(func() Set { return NewSimpleSet() })uSet := Union(set, set2)t.Logf("The set value (2): %v", set2)for _, v := range set.Elements() {if !uSet.Contains(v) {t.Errorf("ERROR: The union set value %v do not contains %v!",uSet, v)t.FailNow()}}for _, v := range set2.Elements() {if !uSet.Contains(v) {t.Errorf("ERROR: The union set value %v do not contains %v!",uSet, v)t.FailNow()}}t.Logf("The set value %v is a unioned set of %v and %v", uSet, set, set2)
}func TestIntersect(t *testing.T) {defer func() {if err := recover(); err != nil {debug.PrintStack()t.Errorf("Fatal Error: %s\n", err)}}()t.Log("Starting TestIntersect...")commonElem := genRandElement()set, _ := genRandSet(func() Set { return NewSimpleSet() })set.Add(commonElem)t.Logf("The set value: %v", set)set2, _ := genRandSet(func() Set { return NewSimpleSet() })set2.Add(commonElem)t.Logf("The set value (2): %v", set2)iSet := Intersect(set, set2)for _, v := range iSet.Elements() {if !set.Contains(v) {t.Errorf("ERROR: The set value %v do not contains %v!",set, v)t.FailNow()}if !set2.Contains(v) {t.Errorf("ERROR: The set value %v do not contains %v!",set2, v)t.FailNow()}}t.Logf("The set value %v is a intersected set of %v and %v", iSet, set, set2)
}func TestDifference(t *testing.T) {defer func() {if err := recover(); err != nil {debug.PrintStack()t.Errorf("Fatal Error: %s\n", err)}}()t.Log("Starting TestDifference...")commonElem := genRandElement()set, _ := genRandSet(func() Set { return NewSimpleSet() })set.Add(commonElem)t.Logf("The set value: %v", set)set2, _ := genRandSet(func() Set { return NewSimpleSet() })set2.Add(commonElem)t.Logf("The set value (2): %v", set2)dSet := Difference(set, set2)for _, v := range dSet.Elements() {if !set.Contains(v) {t.Errorf("ERROR: The set value %v do not contains %v!",set, v)t.FailNow()}if set2.Contains(v) {t.Errorf("ERROR: The set value %v contains %v!",set2, v)t.FailNow()}}t.Logf("The set value %v is a differenced set of %v to %v", dSet, set, set2)
}func TestSymmetricDifference(t *testing.T) {defer func() {if err := recover(); err != nil {debug.PrintStack()t.Errorf("Fatal Error: %s\n", err)}}()t.Log("Starting TestSymmetricDifference...")commonElem := genRandElement()set, _ := genRandSet(func() Set { return NewSimpleSet() })set.Add(commonElem)t.Logf("The set value: %v", set)set2, _ := genRandSet(func() Set { return NewSimpleSet() })set2.Add(commonElem)t.Logf("The set value (2): %v", set2)sdSet := SymmetricDifference(set, set2)for _, v := range sdSet.Elements() {if set.Contains(v) && set2.Contains(v) {t.Errorf("ERROR: The element %v can not be a common element of %v to %v!",v, set, set2)t.FailNow()}}t.Logf("The set value %v is a symmetric differenced set of %v to %v", sdSet, set, set2)
}// ----- 随机测试对象生成函数 -----

func genRandSet(newSet func() Set) (set Set, elemMap map[interface{}]bool) {set = newSet()elemMap = make(map[interface{}]bool)var enough boolfor !enough {e := genRandElement()set.Add(e)elemMap[e] = trueif len(elemMap) >= 3 {enough = true}}return
}func genRandElement() interface{} {seed := rand.Int63n(10000)switch seed {case 0:return genRandInt()case 1:return genRandString()case 2:return struct {num int64str string}{genRandInt(), genRandString()}default:const length = 2arr := new([length]interface{})for i := 0; i < length; i++ {if i%2 == 0 {arr[i] = genRandInt()} else {arr[i] = genRandString()}}return *arr}
}func genRandString() string {var buff bytes.Buffervar prev stringvar curr stringfor i := 0; buff.Len() < 3; i++ {curr = string(genRandAZAscii())if curr == prev {continue} else {prev = curr}buff.WriteString(curr)}return buff.String()
}func genRandAZAscii() int {min := 65 // Amax := 90 // Z
    rand.Seed(time.Now().UnixNano())return min + rand.Intn(max-min)
}func genRandInt() int64 {return rand.Int63n(10000)
}

hash_set_test.go

// hash_set_test
package setimport ("fmt""runtime/debug""strings""testing"
)func TestHashSetCreation(t *testing.T) {defer func() {if err := recover(); err != nil {debug.PrintStack()t.Errorf("Fatal Error: %s\n", err)}}()t.Log("Starting TestHashSetCreation...")hs := NewHashSet()t.Logf("Create a HashSet value: %v\n", hs)if hs == nil {t.Errorf("The result of func NewHashSet is nil!\n")}isSet := IsSet(hs)if !isSet {t.Errorf("The value of HashSet is not Set!\n")} else {t.Logf("The HashSet value is a Set.\n")}
}func TestHashSetLenAndContains(t *testing.T) {testSetLenAndContains(t, func() Set { return NewHashSet() }, "HashSet")
}func TestHashSetAdd(t *testing.T) {testSetAdd(t, func() Set { return NewHashSet() }, "HashSet")
}func TestHashSetRemove(t *testing.T) {testSetRemove(t, func() Set { return NewHashSet() }, "HashSet")
}func TestHashSetClear(t *testing.T) {testSetClear(t, func() Set { return NewHashSet() }, "HashSet")
}func TestHashSetElements(t *testing.T) {testSetElements(t, func() Set { return NewHashSet() }, "HashSet")
}func TestHashSetSame(t *testing.T) {testSetSame(t, func() Set { return NewHashSet() }, "HashSet")
}func TestSetString(t *testing.T) {testSetString(t, func() Set { return NewHashSet() }, "HashSet")
}func testSetOp(t *testing.T) {defer func() {if err := recover(); err != nil {debug.PrintStack()t.Errorf("Fatal Error: %s\n", err)}}()fmt.Println(222)t.Logf("Starting TestHashSetOp...")hs := NewHashSet()if hs.Len() != 0 {t.Errorf("ERROR: The length of original HashSet value is not 0!\n")t.FailNow()}randElem := genRandElement()expectedElemMap := make(map[interface{}]bool)t.Logf("Add %v to the HashSet value %v.\n", randElem, hs)hs.Add(randElem)expectedElemMap[randElem] = trueexpectedLen := len(expectedElemMap)if hs.Len() != expectedLen {t.Errorf("ERROR: The length of HashSet value %d is not %d!\n", hs.Len(), expectedLen)t.FailNow()}var result boolfor i := 0; i < 8; i++ {randElem = genRandElement()t.Logf("Add %v to the HashSet value %v.\n", randElem, hs)result = hs.Add(randElem)if expectedElemMap[randElem] && result {t.Errorf("ERROR: The element adding (%v => %v) is successful but should be failing!\n",randElem, hs)t.FailNow()}if !expectedElemMap[randElem] && !result {t.Errorf("ERROR: The element adding (%v => %v) is failing!\n",randElem, hs)t.FailNow()}expectedElemMap[randElem] = true}expectedLen = len(expectedElemMap)if hs.Len() != expectedLen {t.Errorf("ERROR: The length of HashSet value %d is not %d!\n", hs.Len(), expectedLen)t.FailNow()}for k, _ := range expectedElemMap {if !hs.Contains(k) {t.Errorf("ERROR: The HashSet value %v do not contains %v!", hs, k)t.FailNow()}}number := 2for k, _ := range expectedElemMap {if number%2 == 0 {t.Logf("Remove %v from the HashSet value %v.\n", k, hs)hs.Remove(k)if hs.Contains(k) {t.Errorf("ERROR: The element adding (%v => %v) is failing!\n",randElem, hs)t.FailNow()}delete(expectedElemMap, k)}number++}expectedLen = len(expectedElemMap)if hs.Len() != expectedLen {t.Errorf("ERROR: The length of HashSet value %d is not %d!\n", hs.Len(), expectedLen)t.FailNow()}for _, v := range hs.Elements() {if !expectedElemMap[v] {t.Errorf("ERROR: The HashSet value %v contains %v!", hs, v)t.FailNow()}}hs2 := NewHashSet()for k, _ := range expectedElemMap {hs2.Add(k)}if !hs.Same(hs2) {t.Errorf("ERROR: HashSet value %v do not same %v!\n", hs, hs2)t.FailNow()}str := hs.String()t.Logf("The string of HashSet value %v is '%s'.\n", hs, str)for _, v := range hs.Elements() {if !strings.Contains(str, fmt.Sprintf("%v", v)) {t.Errorf("ERROR: '%s' do not contains '%v'!", str, v)t.FailNow()}}
}

 

转载于:https://www.cnblogs.com/gaopeng527/p/6154977.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/394428.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

c#控件弹幕效果_C# Form 实现桌面弹幕

使用C# Form 简单的实现了弹幕效果1.创建一个Form 设置2.添加一个计时器3. 代码using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Drawing.Text;using System.Linq;using System.Text;using S…

Makefile中怎么使用Shell if判断

/********************************************************************** Makefile中怎么使用Shell if判断* 说明&#xff1a;* 譬如可能会在Makfile中需要判断文件、文件夹的存在&#xff0c;使用shell语法* 输出一些信息&#xff0c;等等。** …

我如何使用React和Typescript在freeCodeCamp中构建天气应用

by Kelvin Mai通过凯文麦 我如何使用React和Typescript在freeCodeCamp中构建天气应用 (How I built the weather app in freeCodeCamp using React and Typescript) So I finally decided to come back to freeCodeCamp and try to finish out my Front End Development Certi…

mysql结果集相减_MySQL_(Java)使用JDBC向数据库发起查询请求

课程相关链接&#xff1a;JDBC编程和MySQL数据库课程源代码在文章末尾~Java Database Connectivity简单来说就是使用Java里面提供的一些类和方法&#xff0c;利用程序链接数据库&#xff0c;进行增删改查操作。这个过程就叫做JDBC编程接下来我们便分五步通过JDBC对MySQL中的数据…

在双系统(Windows与Ubuntu)下删除Ubuntu启动项

问题概述&#xff1a;因为在自己学习Linux的时候&#xff0c;按照网上的教程错误的删除了Ubuntu的一个内核驱动&#xff0c;导致Ubuntu不能启动。我想到的办法是重新安装系统&#xff0c;重装系统的第一步便是将Ubuntu从电脑中卸载。该笔记是有关如何删除Ubuntu启动项的。 使用…

iangularjs 模板_2018-web前端的自我介绍-优秀word范文 (5页)

本文部分内容来自网络整理&#xff0c;本司不为其真实性负责&#xff0c;如有异议或侵权请及时联系&#xff0c;本司将立即删除&#xff01;本文为word格式&#xff0c;下载后可方便编辑和修改&#xff01;web前端的自我介绍篇一&#xff1a;个人总结的web前端面试题1、自我介绍…

Teradata QueryGrid整合最佳分析技术 拓展客户选择空间

ZDNET至顶网CIO与应用频道 05月11日 北京消息&#xff1a; 为持续帮助企业克服数据散布在不同分析系统的困难&#xff0c;全球领先的大数据分析和营销应用服务供应商Teradata天睿公司宣布对Teradata QueryGrid 进行重要技术升级。此次升级新增并强化六项QueryGrid技术&#xf…

神舟笔记本bios_海尔雷神(蓝天)神舟战神游戏本风扇狂转掉电大写灯狂闪维修实例...

昨天收到一台网友寄过来的海尔雷神游戏本。说到这个游戏本品牌&#xff0c;其实有几个品牌的笔记本&#xff0c;它们的主板和模具是一模一样的&#xff0c;也就是我们看到的品牌log不一样而已。比如神舟的战神 &#xff0c;机械师&#xff0c;机械革命&#xff0c;麦本本等等。…

Oracle 学习----:查看当前时间与Sqlserver语句不一样了

oracle:select sysdate from dual sqlserver: select getdate() ---------------------试试这个---------------------------------------------------------- insert into OracleTab values(sysdate) insert into SqlserverTab values(getdate())转载于:https://www.cnblogs…

react发送和接收请求_React行为编程简介:请求,等待和阻止

react发送和接收请求by Luca Matteis卢卡马蒂斯(Luca Matteis) React行为编程简介&#xff1a;请求&#xff0c;等待和阻止 (An intro to Behavioral Programming with React: request, wait, and block) Behavioral Programming (BP) is a paradigm coined in the 2012 artic…

leetcode96. 不同的二叉搜索树(动态规划)

给定一个整数 n&#xff0c;求以 1 … n 为节点组成的二叉搜索树有多少种&#xff1f; 解题思路 *数组含义&#xff1a;dp[i] i个节点的不同组成结构 状态转移&#xff1a;任取节点为根节点&#xff0c;遍历左右子树可能出现的个数,dp[i]dp[left]dp[right] 初始化&#xff1a…

“康园圈--互联网+校园平台“项目之成果展示及项目总结

一、总体效果&#xff08;ipad端截图&#xff09; 网站前台页面网站后台管理台页面二、前台访问链接&#xff08;用pc访问效果最佳&#xff09;&#xff1a;http://www.liangzhilin.cn:9100/kangyuanquan/ &#xff08;为保证数据安全&#xff0c;后台管理链接不对外公开&#…

ajax jq 图片上传请求头_Jquery ajaxsubmit上传图片实现代码

这是数月前的事情了&#xff0c;场景是这样的&#xff1a; 在进行图片上传的时&#xff0c;我发现开发人员使用的上传图片方式是Iframe 传统的 http post 来处理的。而且未建立统一上传函数。于是将代码改造了。心想来个ajax异步上传图片吧&#xff0c;这技术应该很老套了。于…

这个免费的交互式课程在一小时内学习JavaScript

JavaScript is the most popular programming language on the web. You can use it to create websites, servers, games and even native apps. So no wonder it’s such a valuable skill in today’s job market.JavaScript是网络上最流行的编程语言。 您可以使用它来创建网…

java中二进制怎么说_面试:说说Java中的 volatile 关键词?

volatile 这个关键字可能很多朋友都听说过&#xff0c;或许也都用过。在 Java 5 之前&#xff0c;它是一个备受争议的关键字&#xff0c;因为在程序中使用它往往会导致出人意料的结果。在 Java 5之后&#xff0c;volatile 关键字才得以重获生机。volatile 关键字虽然从字面上理…

类的详解

面向对象是一种编程方式&#xff0c;此编程方式的实现是基于对类和对象的使用。类是一个模板&#xff0c;模板中包装了多个“函数”供使用&#xff08;可以讲多函数中公用的变量封装到对象中&#xff09;。对象&#xff0c;根据模板创建的实例&#xff08;即对象&#xff09;&a…

leetcode279. 完全平方数(动态规划)

给定正整数 n&#xff0c;找到若干个完全平方数&#xff08;比如 1, 4, 9, 16, …&#xff09;使得它们的和等于 n。你需要让组成和的完全平方数的个数最少。 示例 1: 输入: n 12 输出: 3 解释: 12 4 4 4. 解题思路 数组含义&#xff1a;dp[i]数字i对应组成和的完全平方…

什么情况不能办理房产抵押贷款 房产抵押贷能贷多少?

所谓房产抵押贷款是指以自己或亲友的房产作为抵押物向贷款机构申请贷款&#xff0c;款项可用于企业经营、买房、买车、装修及其他用途的融资方式。但是有些情况是规定不能申请房产抵押贷款的&#xff0c;而且贷款的数额是有限的&#xff0c;不是想贷多少就多少。那么&#xff0…

Android RecyclerView 二级列表实现

Android RecyclerView 二级列表实现

2数据库表增加一个字段_14个实用的数据库设计技巧!

1. 原始单据与实体之间的关系可以是一对一、一对多、多对多的关系。在一般情况下&#xff0c;它们是一对一的关系&#xff1a;即一张原始单据对应且只对应一个实体。在特殊情况下&#xff0c;它们可能是一对多或多对一的关系&#xff0c;即一张原始单证对应多个实体&#xff0c…